X, Y, N = list(map(int,input().split())) for i in range(N): U, V = list(map(int,input().split())) if U == 0: if V % Y == 0: print(Y) else: print(V % Y) continue U -= 1 V -= 1 if U // Y == V // Y: print(V - U) else: print(U % Y + V % Y + 2)