#include using namespace std; using ll = long long; #define ALL(a) (a).begin(), (a).end() #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define endl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll X, Y, N; cin >> X >> Y >> N; for (; N--;) { ll U, V; cin >> U >> V; ll ans; if ((U - 1) / Y == (V - 1) / Y) { ans = abs(((U % Y == 0 && U != 0) ? Y : U % Y) - ((V % Y == 0 && V != 0) ? Y : V % Y)); } else { ans = ((U % Y == 0 && U != 0) ? Y : U % Y) + ((V % Y == 0 && V != 0) ? Y : V % Y); } cout << ans << endl; } }