N=int(eval(input()))

for _ in[0]*int(eval(input())):

 a,b=list(map(int,input().split()))

 print((min(a-1,N-a,b-1,N-b)%3+1))

import sys

N=int(eval(input()))

eval(input())

for e in sys.stdin:

 a,b=list(map(int,e.split()))

 print((min(a-1,N-a,b-1,N-b)%3+1))

N = int(eval(input()))
for _ in [0] * int(eval(input())):
    a, b = list(map(int, input().split()))
    print((min(a - 1, N - a, b - 1, N - b) % 3 + 1))

import sys

N = int(eval(input()))
eval(input())
for e in sys.stdin:
    a, b = list(map(int, e.split()))
    print((min(a - 1, N - a, b - 1, N - b) % 3 + 1))

+import sys + -for _ in [0] * int(eval(input())): -    a, b = list(map(int, input().split())) +eval(input()) +for e in sys.stdin: +    a, b = list(map(int, e.split()))