#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } template struct FixPoint : F{ FixPoint(F&& f):F(forward(f)){} template decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward(args)...); } }; template inline decltype(auto) MFP(F&& f){ return FixPoint{forward(f)}; } //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector> G(n); for(int i=1;i>a>>b; a--;b--; G[a].emplace_back(b); G[b].emplace_back(a); } vector idx(n); for(int i=0;i>q; int x=0; for(int i=0;i>u>>v; u--;v--; u=(u+x)%n;v=(v+x)%n; swap(idx[u],idx[v]); MFP([&](auto dfs,int v,int p)->void{ int nxt=-1; for(int u:G[v]){ if(u==p) continue; if(nxt<0 or idx[nxt]