X, Y, N = map(int, input().split()) UV = [tuple(map(int, input().split())) for _ in range(N)] def f(x): if x == 0: return 0 elif x != 0 and x % Y == 0: return Y else: return x % Y for a,b in UV: if (a-1) // Y == (b-1) // Y: print((abs(a-b))) else: print(abs(f(a)+f(b)))