#include <bits/stdc++.h>
using namespace std;
#define int long long int
template<class T> auto vec(int r, int c, T v){ return vector<vector<T>>(r, vector<T>(c, v)); }
template<class T> auto vec(int o1, int o2, int o3, T v){ return vector<vector<vector<T>>>(o1, vector<vector<T>>(o2, vector<T>(o3, v))); }
int power(int x, int n, int m = -1){
    if(m != -1) x %= m;
    int ans = 1;
    while(n > 0){
        if( n & 1 ) {
            ans *= x;
            if(m != -1) ans = ans % m;
        }
        x = x * x;
        if(m != -1) x = x % m;
        n >>= 1;
    }
    return ans;
}
#define dbg(x) cerr << "[" << #x << " = " << x << "] ";
#define dbga(x, l, r) { cerr << "[" << #x << " = "; for(int i = l; i <= r; i++) { cerr << x[i]; if(i != r) cerr << ", ";} cerr << "]"; }
#define ub(x, y) (upper_bound(x.begin(), x.end(), y) - x.begin())
#define lb(x, y) (lower_bound(x.begin(), x.end(), y) - x.begin())

int TIME = 0;

void DFS(auto &adj, auto &dp, auto &d, auto &in, auto &out, int u = 0, int p = -1, int h = 0) {
    d[u] = h;
    in[u] = TIME++;
    dp[h].push_back(in[u]);
    for(int v : adj[u]) {
        if(v == p) continue;
        DFS(adj, dp, d, in, out, v, u, h + 1);
    }
    out[u] = TIME++;
}


signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    vector<int> p(n, -1);
    vector<vector<int>> adj(n);
    vector<vector<int>> dp(n);
    vector<int> d(n, 0), in(n), out(n);
    for(int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        adj[p[i]].push_back(i);
        adj[i].push_back(p[i]);
    }
    DFS(adj, dp, d, in, out);
    int q; cin >> q;
    for(int qq = 0, u, d; qq < q; qq++) {
        cin >> u >> d;
        u--;
        cout << lb(dp[d], out[u]) - lb(dp[d], in[u]) << "\n";
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REPP(i,a,b,d) for(int i=(a);i<=(int)(b);i+=(d))
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=(a);i>=(int)(b);i-=(d))
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) for(int i=0; i<(int)(a); i++)
#define FORD(i,a) for(int i=(int)(a)-1; i>=0; i--)
#define pb push_back
typedef long long ll;

struct Matrix {
	ll a, b, c, d;
};

struct Point {
	ll x, y;
};

const int N = 2e5+5;
int n, m, q;
Point a[N];
pair<int, int> op[N];
vector<pair<int, int>> queries[N];
Point ans[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, 1, n) cin >> a[i].x >> a[i].y;
	cin >> m;
	REP(i, 1, m) {
		cin >> op[i].first;
		if(op[i].first > 2) cin >> op[i].second;
	}
	cin >> q;
	FOR(i, q) {
		int x, y; cin >> x >> y;
		queries[x].pb({y, i});
	}

	Matrix mul = {1, 0, 0, 1};
	Point add = {0, 0};

	REP(i, 0, m) {
		if(i > 0) {
			if(op[i].first == 1) {
				mul = {mul.c, mul.d, -mul.a, -mul.b};
				add = {add.y, -add.x};
			} else if(op[i].first == 2) {
				mul = {-mul.c, -mul.d, mul.a, mul.b};
				add = {-add.y, add.x};
			} else if(op[i].first == 3) {
				mul = {-mul.a, -mul.b, mul.c, mul.d};
				add = {-add.x, add.y};
				add.x += 2 * op[i].second;
			} else {
				mul = {mul.a, mul.b, -mul.c, -mul.d};
				add = {add.x, -add.y};
				add.y += 2 * op[i].second;
			}
		}
		for(auto &q : queries[i]) {
			int &idx = q.first, &id = q.second;
			Point nw;
			nw.x = mul.a * a[idx].x + mul.b * a[idx].y;
			nw.y = mul.c * a[idx].x + mul.d * a[idx].y;
			nw.x += add.x, nw.y += add.y;
			ans[id] = nw;
		}
	}

	FOR(i, q) cout << ans[i].x << ' ' << ans[i].y << '\n';

	return 0;
}