#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 20
#define INF 1000000005
#define INFLL (ll)1000000000000000005
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
#define per(a,mod) ((a)%(mod)+(mod))%(mod)
typedef pair<int,int> P;
const int MAX = (1<<20);
const int MOD = 998244353;

ll dp[MAX][3][3];
void solve(){
    int n;
    cin>>n;
    vector<int>x(n),y(n);
    REP(i,n)cin>>x[i]>>y[i];
    int m;
    cin>>m;
    REP(i,3)dp[0][i][i]=1;
    REP(t,m){
        int c;
        cin>>c;
        if(c==1){
            ll w[3][3]={{0,1,0},{-1,0,0},{0,0,1}};
            REP(i,3){
                REP(j,3){
                    REP(k,3){
                        dp[t+1][i][j]+=w[i][k]*dp[t][k][j];
                    }
                }
            }
        }else if(c==2){
            ll w[3][3]={{0,-1,0},{1,0,0},{0,0,1}};
            REP(i,3){
                REP(j,3){
                    REP(k,3){
                        dp[t+1][i][j]+=w[i][k]*dp[t][k][j];
                    }
                }
            }
        }else if(c==3){
            ll p;
            cin>>p;
            ll w[3][3]={{-1,0,2*p},{0,1,0},{0,0,1}};
            REP(i,3){
                REP(j,3){
                    REP(k,3){
                        dp[t+1][i][j]+=w[i][k]*dp[t][k][j];
                    }
                }
            }
        }else{
            ll p;
            cin>>p;
            ll w[3][3]={{1,0,0},{0,-1,2*p},{0,0,1}};
            REP(i,3){
                REP(j,3){
                    REP(k,3){
                        dp[t+1][i][j]+=w[i][k]*dp[t][k][j];
                    }
                }
            }
        }
        
    }
    int Q;
        cin>>Q;
        vector<int>ra(Q),rb(Q);
        REP(i,Q){
            cin>>ra[i]>>rb[i];
            rb[i]--;
        }
        REP(i,Q){
            int a=ra[i],b=rb[i];
            ll ax=dp[a][0][0]*x[b]+dp[a][0][1]*y[b]+dp[a][0][2];
            ll ay=dp[a][1][0]*x[b]+dp[a][1][1]*y[b]+dp[a][1][2];
            cout<<ax<<" "<<ay<<endl;
        }
}
int main(){
    solve();
    return 0;
}

#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
using LL = long long;
const int M = 1e9 + 7;

int main() {
	// freopen("in", "r", stdin);
	std::cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	std::cin >> n;
	std::vector<std::vector<std::pair<int, LL>>> e(n + 1);
	for (int i = 1, u, v; i < n; ++i) {
		LL w;
		std::cin >> u >> v >> w;
		e[u].emplace_back(v, w);
		e[v].emplace_back(u, w);
	}
	std::vector<LL> val(n + 1);
	std::function<void(int, int)> dfs = [&](int u, int fa) {
		for (auto &[v, w] : e[u]) if (v != fa) {
			val[v] = val[u] ^ w;
			dfs(v, u);
		}
	};
	dfs(1, 0);
	const int N = 60;
	std::vector<int> cnt(N);
	for (auto x : val) {
		for (int i = 0; x; x >>= 1, ++i) if (x & 1) ++cnt[i];
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = (ans + (1LL << i) % M * cnt[i] % M * (n - cnt[i])) % M;
	}
	std::cout << ans << '\n';
	return 0;
}