import sys from collections import * from functools import cache, partial from itertools import * from pprint import pprint from typing import Any, Final try: from icecream import ic except ImportError: # Graceful fallback if IceCream isn't installed. ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a) # noqa debug = partial(print, file=sys.stderr) dpprint = partial(pprint, stream=sys.stderr) sys.setrecursionlimit(10 ** 6) MOD=998244353 X, Y, N = map(int, input().split()) # ic(X, Y) for _ in range(N): u, v = map(int, input().split()) # ic(u, v) if u == 0 and v == 0: ans = 0 elif u == 0: ans = (v - 1) % Y + 1 elif v == 0: ans = (u - 1) % Y + 1 else: s, t = (u - 1) // 3, (v - 1) // 3 # ic(s, t) if s == t: # 同じ枝 ans = abs(u - v) else: # 違う枝 # 0 からの距離を求める ans = (u - 1) % Y + (v - 1) % Y + 2 print(ans)