#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M,q; cin >> N >> M >> q; vector> LR(M); vector P(N),Q(N); iota(P.begin(),P.end(),0),iota(Q.begin(),Q.end(),0); for(auto &[l,r] : LR){ cin >> l >> r,l--,r--; int pl = Q.at(l),pr = Q.at(r); swap(P.at(pl),P.at(pr)),swap(Q.at(l),Q.at(r)); } vector> To(N,vector(60)); for(int i=0; i answer(q); vector>> Query(M); for(int i=0; i> t >> x,x--; Query.at(t%M).push_back({t/M,x,i}); } iota(P.begin(),P.end(),0),iota(Q.begin(),Q.end(),0); for(int i=0; i>d)&1) pos = To.at(pos).at(d); answer.at(qpos) = pos; } auto [l,r] = LR.at(i); int pl = Q.at(l),pr = Q.at(r); swap(P.at(pl),P.at(pr)),swap(Q.at(l),Q.at(r)); } for(auto a : answer) cout << a+1 << "\n"; }