#include #include #include using namespace std; using ll = long long; int main(){ ll x,y,n; cin >> x >> y >> n; while(n--){ ll u,v; cin >> u >> v; if(u==0){ cout << (v-1)%y+1 << endl;; }else if((u-1)/y== (v-1)/y){ cout << abs(u-v)<< endl; }else{ cout << (u-1)%y+1 + (v-1)%y+1 << endl; } } return 0; }