Li Zicheng and Tibetans were fought against by the Monguors, who supported the Ming, and when the Qing fought against Li's forces after 1644 they joined the Qing side. Late in 1646, forces assembled by a Muslim leader known in Chinese sources as Milayin  revolted against Qing rule in Ganzhou . He was soon joined by another Muslim named Ding Guodong . Proclaiming that they wanted to restore the fallen Ming, they occupied a number of towns in Gansu, including the provincial capital Lanzhou. These rebels' willingness to collaborate with non-Muslim Chinese suggests that they were not only driven by religion, and were not aiming to create an Islamic state. To pacify the rebels, the Qing government quickly despatched Meng Qiaofang , governor of Shaanxi, a former Ming official who had surrendered to the Qing in 1631. Both Milayin and Ding Guodong were captured and killed in 1648, and by 1650 the Muslim rebels had been crushed in campaigns that inflicted heavy casualties. The Muslim Ming loyalists were supported by the Muslim Chagatid Kumul Khanate and the Turfan Khanate and after their defeat, Kumul submitted to the Qing. Another Muslim rebel, Ma Shouying, was allied to Li Zicheng and the Shun dynasty.
Question: What happened first, they joined the Qing side or they had surrendered to the Qing?
Answer: had surrendered to the Qing