#include using namespace std; using ll = long long; #ifdef LOCAL #include #else #define debug(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll 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 << (V - 1) % Y + 1 + (U - 1) % Y + 1 << '\n'; } } }