In late July, Danzig was re-inforced by a Dutch garrison, and a combined Danish and Dutch fleet broke the naval blockage imposed on Danzig by Charles X Gustav. On 28-30 July, a combined Brandenburgian-Swedish army was able to defeat the Polish-Lithuanian army in the Battle of Warsaw, forcing John II Casimir to retreat to Lublin. In August, Alexis' army took Livonian Kokenhausen , laid siege to Riga and Dorpat  and raided Estonia, Ingria and Kexholm. On 4 October, John II Casimir stormed Łęczyca in Greater Poland before heading for Royal Prussia, and on 8 October, Wincenty Korwin Gosiewski with 12,000 to 13,000 Lithuanian and Crimean Tartar cavalry overran a Brandenburgian-Swedish force in the Battle of Prostken in Ducal Prussia. Gosiewski then ravaged Ducal Prussia, burning 13 towns and 250 villages, in a campaign that entered folklore because of the high death toll and the high number of captives deported to the Crimea. On 22 October, Gosiewski was defeated by Swedish forces in the Battle of Filipów and turned to Lithuania. Also on 22 October, besieged Dorpat surrendered to Alexis, while the Russian siege of Swedish-held Riga was lifted. John II Casimir meanwhile took Bromberg  and Konitz in Royal Prussia, and from 15 November 1656 until February 1657 stayed in Danzig, where a Swedish siege had to be lifted due to Dutch intervention, just 55 kilometers away from Charles X Gustav's quarters in Elbing.
Answer this question: What happened first: Casimir retreated to Lublin or Gosiewski was defeated by Swedish?
Casimir retreated to Lublin