s="123" place=input() n=input() for q in range(n): x,y=map(int,input().split()) s[x-1],s[y-1]=s[y-1],s[x-1] if place==int(s[0]): print(1) elif place==int(s[1]): print(2) else: print(3)