X,Y,N=map(int,input().split()) for _ in range(N): U,V=map(int,input().split()) if (U-1)//Y==(V-1)//Y or U==0 or V==0: if U==0: print((V-1)%Y+1) elif V==0: print((U-1)%Y+1) else: print(max(U,V)-min(U,V)) else: print((U-1)%Y+1+(V-1)%Y+1)