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