#include #include using namespace atcoder; using namespace std; // using mint = atcoder::modint998244353; using ll = long long; const int INF = 1001001001; const ll LINF = 3001001001001001001; const int MOD = 998244353; const string Yes = "Yes"; const string No = "No"; #define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define rep(i, n) reps(i, 0, n) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} template istream &operator>>(istream &is, vector &v) {for (T &in : v)is >> in;return is;} vector> dir4 = {{0,1},{0,-1},{1,0},{-1,0},}; vector> dir8 = {{0,1},{0,-1},{1,0},{-1,0},{-1,-1},{-1,1},{1,-1},{1,1},}; int main() { ll x,y;cin>>x>>y; int Q;cin>>Q; while(Q--) { ll u,v;cin>>u>>v; ll s = u%y; if(u!=0&&u%y==0) s = y; ll t = v%y; if(v!=0&&v%y==0) t = y; if((u-1)/y==(v-1)/y) { cout << abs(s-t) << endl; } else { cout << s+t << endl; } } return 0; }