#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<ll,ll>
using Graph = vector<vector<int>>;

int main() {
    ll N,M,Q; cin >> N;
    ll x[N+1],y[N+1];
    rep(i,N){
        cin >> x[i+1] >> y[i+1];
    }
    
    vector<P> op; ll a,b,c; cin >> M;
    rep(i,M){
        cin >> a;
        if(a==1||a==2) op.push_back(make_pair(a,0));
        else{
            cin >> b;
            op.push_back(make_pair(a,b));
        }
    }
    
    //Query(input / tuple化/順次処理)
    cin >> Q;
    vector<tuple<int,int,int>> q;
    for(int i=0;i<Q;i++){
        cin >> a >> b;
        q.push_back(make_tuple(a,b,i));
    }
    
    //必要ならsort
    sort(q.begin(),q.end());
    vector<P> ans(Q);
    ll cnt = 0;
    ll xm[3],ym[3];
    xm[0] = 0; ym[0] = 0; xm[1] = 1; ym[1] = 0;
    xm[2] = 0; ym[2] = 1;
    for(ll i=0;i<Q;i++){
        tuple<int,int,int> qn = q.at(i);
        a = get<0>(qn);
        b = get<1>(qn);
        c = get<2>(qn);
        //ここに処理を追記
        while(cnt<a){
            auto p = op[cnt];
            ll s = p.first; ll t = p.second;
            cnt++; //cout << cnt << endl;
            //rotate, flip
            if(s==1){
                rep(j,3){
                    xm[j] *= -1;
                    swap(xm[j],ym[j]);
                }
            }
            if(s==2){
                rep(j,3){
                    ym[j] *= -1;
                    swap(xm[j],ym[j]);
                }
            }
            if(s==3){
                rep(j,3){
                    xm[j] = 2*t-xm[j];
                }
            }
            if(s==4){
                rep(j,3){
                    ym[j] = 2*t-ym[j];
                }
            }
        }
        //座標復元
        ll xa,ya;
        ll dx1 = xm[1]-xm[0]; ll dy1 = ym[1]-ym[0];
        ll dx2 = xm[2]-xm[0]; ll dy2 = ym[2]-ym[0];
        xa = xm[0] + dx1*x[b] + dx2*y[b]; 
        ya = ym[0] + dy1*x[b] + dy2*y[b];
        ans[c] = make_pair(xa,ya);
    }
    for(ll i=0;i<Q;i++){
        cout << ans[i].first <<" "<< ans[i].second << endl;
    }
}
#include<bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())
 
using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;
 
template<typename T> bool chmin(T& a, const T& b) { if(a >= b){ a = b; return 1;} return 0; }
template<typename T> bool chmax(T& a, const T& b) { if(a <= b){ a = b; return 1;} return 0; }


const ll MOD = 998244353;
const ll INF = 1e9;

//BIT
template <typename T>
struct BIT{
    int n;  //配列の要素数
    vector<T> bit;  //データの格納先
    BIT(int n_) : n(n_ + 1), bit(n, 0){}

    void add(int i, T x){
        for(int idx = i; idx < n; idx += (idx & -idx)){
            bit[idx] += x;
        }
    }

    T sum(int i){
        T s(0);
        for(int idx = i; idx > 0; idx -= (idx & -idx)){
            s += bit[idx];
        }
        return s;
    }

    //sum(a_i) >= w となるような最小のxを求める
    int lower_bound(T w) { // a_1 + a_2 + ... + a_x >= w となるような最小の x を求める(ただし a_i >= 0)
    if (w <= 0) return 0;
    else {
        int x = 0, r = 1;
        while (r < n) r = r << 1;
            for (int len = r; len > 0; len = len >> 1) { // 長さlenは1段下るごとに半分に
                if (x + len < n && bit[x + len] < w) { // 採用するとき
                    w -= bit[x + len];
                    x += len;
                }
            }
            return x + 1;
        }
    }
    

    T num(int i){
        T res = sum(i);
        if(i != 1)res -= sum(i - 1);
        return res;
    }
};
vector<vector<int>> G;
vector<int> eul, dep;
void dfs(int v, int p){
    eul.pb(v);
    for(auto nv : G[v]){
        if(nv == p)continue;
        dep[nv] = dep[v] + 1;
        dfs(nv, v);
    }
    eul.pb(v);
}
int main(){
    int n;
    cin >> n;
    G.resize(n);
    dep.resize(n);
    vector<int> p(n - 1);
    rep(i, n - 1)cin >> p[i];
    rep(i, n - 1){
        p[i]--;
        G[i + 1].pb(p[i]);
        G[p[i]].pb(i + 1);
    }
    int q;
    cin >> q;
    vector<int> U(q), D(q);
    rep(i, q)cin >> U[i] >> D[i];
    //Dごとに管理する
    vector<vector<P>> qry(n + 1);
    rep(i, q){
        U[i]--;
        qry[D[i]].pb(P(U[i], i));
    }
    dfs(0, -1);
    //dep[v] -> v
    vector<vector<int>> rdep(n + 1);
    rep(i, n){
        rdep[dep[i]].pb(i);
    }
    //vを根とする部分木に対応する区間を持つ
    vector<int> L(n, -1), R(n);
    rep(i, sz(eul)){
        if(L[eul[i]] == -1)L[eul[i]] = i;
        R[eul[i]] = i;
    }
    BIT<int> bit(sz(eul));
    vector<int> res(q);
    REP(i, 0, n){
        //bitに深さiの点を加える
        for(auto v : rdep[i]){
            bit.add(L[v] + 1, 1);
        }
        //クエリ処理
        for(auto qi : qry[i]){
            auto [ui, id] = qi;
            res[id] = bit.sum(R[ui] + 1);
            if(L[ui] > 0)res[id] -= bit.sum(L[ui]);
        }
        //足した分引く
        for(auto v : rdep[i]){
            bit.add(L[v] + 1, -1);
        }
    }
    for(auto ri : res)cout << ri << endl;
}