#include using namespace std; #ifdef LOCAL #define debug(x) cerr << #x << " = " << (x) << "\n" #else #define debug(x) void(0) #endif typedef long long ll; typedef long double ld; typedef pair Pii; typedef pair Pll; template ostream &operator<<(ostream &os, const vector &v) { for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 == (int)v.size() ? "" : " "); return os; } template istream &operator>>(istream &is, vector &v) { for (int i = 0; i < (int)v.size(); i++) is >> v[i]; return is; } //////////////////////////////////////////////////////////// int main() { int X, Y, N; cin >> X >> Y >> N; while (N--) { ll U, V; cin >> U >> V; if (U == 0) cout << (V - 1) % Y + 1 << "\n"; else if ((U - 1) / Y == (V - 1) / Y) cout << V - U << "\n"; else cout << (U - 1) % Y + (V - 1) % Y + 2 << "\n"; } return 0; }