from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right from itertools import permutations, combinations from heapq import heappop, heappush import math, sys # input = sys.stdin.readline _int = lambda x: int(x)-1 MOD = 998244353 #10**9+7 INF = 1<<60 Yes, No = "Yes", "No" X, Y, N = map(int, input().split()) def same(u, v): if u == 0: return False return (u-1)//Y == (v-1)//Y for _ in range(N): u, v = map(int, input().split()) if same(u, v): print(v-u) elif u == 0: print((v-1)%Y+1) else: print((u-1)%Y+(v-1)%Y+2)