#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; ll INF = 2e18; template using vc = vector; template using vv = vc>; #define MP(a, b) make_pair(a, b) #define nfor(i,s,n) for(ll i=s;i<(ll)n;i++) #define rep(i,n) for(ll i = 0; i < (n); i++) using vl = vc; using vvl = vv; using vvvl = vv; using vvvvl = vv; using vs = vc; using vvs = vv; using vb = vc; using vvb = vv; using vvvb = vv; using vld = vc; using vvld = vv; using vvvld = vv; using P = pair; templateistream& operator>>(istream& i, vc& v) { rep(j, size(v))i >> v[j]; return i; } template using pq = priority_queue>;//大きい順 template using pq_g = priority_queue, greater>;//小さい順 #define pb push_back #define pob pop_back #define all(s) s.begin(),s.end() #define YES std::cout<<"Yes"<; using vvm = vc; int main(){ ll x, y, n; cin >> x >> y >> n; rep(i, n){ ll a, b; cin >> a >> b; if(a == b){ cout << 0 << endl; continue; } if(a == 0 || b == 0){ a = max(a - 1, 0LL); b = max(b - 1, 0LL); cout << max(a % y, b % y) + 1 << endl; continue; } a--, b--; if(a / y == b / y){ cout << abs(a - b) << endl; }else{ cout << a % y + b % y + 2 << endl; } } }