#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a ll op(ll a,ll b){ return a^b; } ll e(){ return 0; } ll mpg(ll f,ll x){ return f^x; } ll comp(ll f,ll g){ return f^g; } ll id(){ return 0; } struct tree{ int n,max_k=1; vector> g; vector> parent; vector depth; tree(int g_size){ n=g_size; g.resize(n); } void add_edge(int u,int v){ g[u].push_back(v); g[v].push_back(u); } void LCA(int root=0){ while((1<(n,-1)); depth.assign(n,-1); dfs(root,-1,0); for(int k=0;k+1> g; vector par,sz,in,out,head; int in_ord=0,out_ord=0; HLD(int x){ n=x; g.resize(n); par.resize(n); sz.assign(n,0); in.resize(n); out.resize(n); head.resize(n); } void add_edge(int u,int v){ g[u].push_back(v); g[v].push_back(u); } void dfs_sz(int x,int p){ sz[x]++; if(0> query(int u,int v,bool edge){ vector> ret; while(true){ if(in[v]> n; ll sz=n+n-1; vector p(n,-1); tree g(sz); HLD h(sz); replr(i,1,n){ cin >> p[i]; p[i]--; g.add_edge(i,n+i-1); g.add_edge(p[i],n+i-1); h.add_edge(i,n+i-1); h.add_edge(p[i],n+i-1); } string s(n,'x'); replr(i,1,n) cin >> s[i]; ll q; cin >> q; vector u(q),v(q); rep(i,q){ cin >> u[i] >> v[i]; u[i]--; v[i]--; } g.LCA(); rep(i,q){ ll x=g.get_lca(u[i],v[i]); ll nu=u[i],nv=v[i]; if(u[i]==x){ nu=g.doubling(v[i],g.depth[v[i]]-g.depth[u[i]]-1); }else{ nu=g.parent[0][u[i]]; } if(v[i]==x){ nv=g.doubling(u[i],g.depth[u[i]]-g.depth[v[i]]-1); }else{ nv=g.parent[0][v[i]]; } u[i]=nu; v[i]=nv; } h.solve(0); vector out(sz),ord(sz); rep(i,sz) out[i]=h.out[i]; rep(i,sz) ord[out[i]]=i; vector> lr(sz); rep(i,q){ if(out[v[i]] seg(sz); auto update=[&](ll a,ll b,ll x){ auto now=h.query(a,b,false); for(auto [l,r]:now){ seg.apply(l,r,x); } }; auto get=[&](ll a,ll b){ auto now=h.query(a,b,false); ll ret=0; for(auto [l,r]:now){ ret^=seg.prod(l,r); } return ret; }; replr(i,1,n){ update(n+i-1,n+i-1,s[i]=='#'); } for(auto i:ord){ if(get(i,i)==0) continue; if(lr[i].empty()) continue; ll j=*begin(lr[i]); update(i,j,1); lr[i].erase(j); if(len(lr[i])