X, Y, N = map(int, input().split()) def same_group(u, v): return (u - 1) // Y == (v - 1) // Y for _ in range(N): u, v = map(int, input().split()) if u == 0: print((v - 1) % Y + 1) elif same_group(u, v): print(v - u) else: c1 = (u - 1) % Y + 1 c2 = (v - 1) % Y + 1 print(c1 + c2)