// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	vi x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];

	int m;
	cin>>m;
	vvi dp;
	// left, up, right, down
	dp.pb({0,0,2,1});

	rep(i,m){
		int q;
		cin>>q;
		vi t=dp.back();
		if(q==1){
			(t[2]+=1)%=4;
			(t[3]+=1)%=4;
			int nx=t[1],ny=-t[0];
			t[0]=nx;
			t[1]=ny;
		}else if(q==2){
			(t[2]+=3)%=4;
			(t[3]+=3)%=4;
			int nx=-t[1],ny=t[0];
			t[0]=nx;
			t[1]=ny;
		}else if(q==3){
			int a;cin>>a;
			if(t[2]==0||t[2]==2){
				(t[2]+=2)%=4;
				t[0]=2*a-t[0];
			}else{
				(t[3]+=2)%=4;
				t[0]=2*a-t[0];
			}
		}else{
			int a;cin>>a;
			if(t[2]==1||t[2]==3){
				(t[2]+=2)%=4;
				t[1]=2*a-t[1];
			}else{
				(t[3]+=2)%=4;
				t[1]=2*a-t[1];
			}
		}
		dp.pb(t);
	}

	int q;
	cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;b--;
		if(dp[a][2]==0||dp[a][2]==2)
			cout<<dp[a][0]+dx[dp[a][2]]*x[b]<<" "<<dp[a][1]+dy[dp[a][3]]*y[b]<<endl;
		else
			cout<<dp[a][0]+dx[dp[a][3]]*y[b]<<" "<<dp[a][1]+dy[dp[a][2]]*x[b]<<endl;
		 	// cout<<dp[a][1]+dx[dp[a][3]]*y[b]<<" "<<dp[a][0]+dy[dp[a][2]]*x[b]<<endl;
	}
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
// #define TEST_CASES
// #define ONLINE_JUDGE

#define test   \
  long long t; \
  cin >> t;    \
  while (t--)
#ifndef ONLINE_JUDGE
#define reach(x) cout << "\n\t\t" << x << "\n\n";
#define deb(x) cout << #x << " " << x << '\n';
#define deb2(x, y) cout << #x << " --> " << x << " || " << #y << " --> " << y << '\n';
#define deb4(a, b, c, d) cout << #a << " = " << a << ", " << #b << " = " << b << ", " << #c << " = " << c << ", " << #d << " = " << d << '\n';
#else
#define reach(x)         //
#define deb(x)           //cout << #x << " " << x << '\n';
#define deb2(x, y)       //cout << #x << " --> " << x << " || " << #y << " --> " << y <<'\n';
#define deb4(a, b, c, d) // cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<'\n';
#endif
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; i < n; i++)
#define boost()                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cout << fixed << setprecision(11);
#define MEM(a, val) memset(a, val, sizeof(a));
#define inputarr(a, n)        \
  for (int i = 0; i < n; ++i) \
  cin >> a[i]

const long long INF = LONG_LONG_MAX, MOD = 1e9 + 7;

typedef long long ll;
typedef long double ld;
using namespace std;

void solve()
{
  ll n, i, j;
  cin >> n;
  vector<ll> r, g, b;
  //logic start
  char ch;
  ll a;
  fo(i, 2 * n)
  {
    cin >> a >> ch;
    if (ch == 'R')
      r.push_back(a);
    else if (ch == 'G')
      g.push_back(a);
    else
      b.push_back(a);
  }
  ll gs = g.size();
  ll rs = r.size();
  ll bs = b.size();
  if (rs % 2 == 0 && gs % 2 == 0 && bs % 2 == 0)
  {
    cout << 0LL;
    return;
  }
  if (rs % 2 == 0)
  {
    swap(r, g);
  }
  else if (bs % 2 == 0)
    swap(b, g);
  rs = r.size();
  bs = b.size();
  sort(b.begin(), b.end());
  sort(r.begin(), r.end());
  // sort(b.begin(), b.end());
  ll ri = 0, bi = 0;
  ll ans = abs(r[0] - b[0]);
  for (ri = 0; ri < rs; ++ri)
  {
    ll ele = lower_bound(b.begin(), b.end(), r[ri]) - b.begin();
    // deb(ele);

    if (ele != bs)
      ans = min(ans, abs(r[ri] - b[ele]));
    if (ele != 0)
      ans = min(ans, abs(r[ri] - b[ele - 1]));
  }
  if (g.size())
  {
    ll res1 = abs(g[0] - r[0]), res2 = abs(g[0] - b[0]);
    for (ll x : g)
    {
      ll ele = lower_bound(b.begin(), b.end(), x) - b.begin();
      // deb(ele);
      if (ele != bs)
        res2 = min(res2, abs(x - b[ele]));
      if (ele != 0)
        res2 = min(res2, abs(x - b[ele - 1]));

      ele = lower_bound(r.begin(), r.end(), x) - r.begin();
      // deb(ele);
      if (ele != rs)
        res1 = min(res1, abs(x - r[ele]));
      if (ele != 0)
        res1 = min(res1, abs(x - r[ele - 1]));
    }
    ans = min(ans, res1 + res2);
  }
  cout << ans;
}

signed main()
{
#ifdef ONLINE_JUDGE
  boost()
#endif
#ifdef TEST_CASES
      test
#endif
  {
#ifdef TEST_CASES
    // reach("--------------------------------------------");
#endif
    solve();
#ifdef TEST_CASES
    cout << '\n';
    // reach("--------------------------------------------");
#endif
  }

  return 0;
}
