Shahrin is accusative in sāfartu fī shahrin.
Al-Mafʿūl Fīhi: Adverbials of Time and Place