#include #include using namespace std; using namespace atcoder; // #include // using namespace boost::multiprecision; // # pragma GCC target("avx2") // # pragma GCC optimize("O3") // # pragma GCC optimize("unroll-loops") #define ll long long #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define vi vector #define vl vector #define vd vector #define vb vector #define vs vector #define vc vector #define ull unsigned long long #define chmax(a,b) a=max(a,b) #define chmin(a,b) a=min(a,b) ll inf=(1ll<<60); // const double PI=3.1415926535897932384626433832795028841971; // ll rui(ll a,ll b){ // if(b==0)return 1; // if(b%2==1) return a*rui(a*a,b/2); // return rui(a*a,b/2); // } // ll kai(ll n){ // if(n==0)return 1; // return n*kai(n-1); // } // using mint = modint998244353;//static_modint<998244353> // using mint = modint1000000007;//static_modint<1000000007> // using mint = modint;//mint::set_mod(mod); // ll const mod=1000000007ll; // ll const mod=998244353ll; // ll modrui(ll a,ll b,ll mod){ // a%=mod; // if(b==0)return 1; // if(b%2==1) return a*modrui(a*a%mod,b/2,mod)%mod; // return modrui(a*a%mod,b/2,mod)%mod; // } // ll inv(ll x){ // x%=mod; // return modrui(x,mod-2); // } // ll modkai(ll n){ // ll ret=1; // rep(i,n){ // ret*=(i+1)%mod; // ret%=mod; // } // return ret; // } // void incr(vl &v,ll n){ // ll k=v.size(); // v[k-1]++; // ll now=k-1; // while (v[now]>=n) // { // v[now]=0; // if(now==0)break; // v[now-1]++; // now--; // } // return; // } void solve(){ ll x,y,n; cin >> x >> y >> n; rep(i,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 << (v-u)%y << endl; else{ cout << (v-1)%y+(u-1)%y+2 << endl; } } } } int main(){ // ios::sync_with_stdio(false); // std::cin.tie(nullptr); ll t=1; // cin >> t; while(t--)solve(); }