X,Y,N=map(int,input().split()) for i in range(N): U,V=map(int,input().split()) if U==0 and V==0: print(0) elif U==0: print((V-1)%Y+1) elif V==0: print((U-1)%Y+1) #同じ腕の中なら単に差分 elif (U-1)//Y==(V-1)//Y: print(abs(U-V)) else: print((U-1)%Y+(V-1)%Y+2)