// Jai Shree Ram  
  
#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC



template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}


int solve(){
 		int n,m; cin >> n >> m;

 		vector<vector<pii>>vec(n+1);

 		rep(i,0,m){
 			int x,y,z; cin >> x >> y >> z;
 			y--;
 			vec[x].push_back({y,z});
 		}
 		vector<vector<int>>dp(n+1,vector<int>(1 << n));
 		dp[0][0] = 1;


 		for(int i = 1; i <= n; i++){
 			sort(all(vec[i]));

 			for(int mask = 0; mask < (1 << n); mask++){
 				int z = __builtin_popcount(mask);
 				if(z != i){
 					continue;
 				}
 				vector<int>t;

 				for(int j = 0; j < n; j++){
 					if((1<<j)&mask)t.push_back(j);
 				}
 				int j = 0;
 				bool bad = 0;
 				for(auto [y,z]:vec[i]){
 					while(j < t.size() and t[j] <= y){
 						j++;
 					}
 					if(j > z)bad=1;
 				}
 				if(bad)continue;
 				for(int j = 0; j < n; j++){
 					if(mask&(1<<j)){
 						dp[i][mask] += dp[i-1][mask^(1 << j)];
 					}
 				}
 			}
 		}
 		cout << dp[n][(1<<n)-1] << endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "[ ";
  for (auto const &x : v) {
    os << x;
    if (&x != &v.back()) {
      os << " : ";
    }
  }
  os << " ]" << endl;
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, vector<vector<T>> &v) {
  os << "[" << endl;
  for (auto const &x : v) {
    os << " ";
    print_vec(x);
  }
  os << "]" << endl;
  return os;
}

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

struct P {
  ll x = 0;
  ll y = 0;

  P &operator+=(const P &p) {
    x += p.x;
    y += p.y;
    return *this;
  }
  P &operator-=(const P &p) {
    x -= p.x;
    y -= p.y;
    return *this;
  }

  P operator+(const P &p) const {
    P _p = *this;
    return _p += p;
  }
  P operator-(const P &p) const {
    P _p = *this;
    return _p -= p;
  }

  ll operator&(const P &p) const { return x * p.y - y * p.x; }
};

ostream &operator<<(ostream &os, P p) {
  os << p.x << " " << p.y;
  return os;
}

void rotate(P &p, ll n) {
  if (n < 0) {
    n = n + ((-n - 1) / 4 + 1) * 4;
  }

  ll x = p.x;
  if (n == 1) {
    p.x = p.y;
    p.y = -x;
  } else if (n == 2) {
    p.x = -p.x;
    p.y = -p.y;
  } else if (n == 3) {
    p.x = -p.y;
    p.y = x;
  }
}

void rotateX(P &p, ll x) { p.x = 2 * x - p.x; }
void rotateY(P &p, ll y) { p.y = 2 * y - p.y; }

void apply(P &p, P &vx, P &vy, P &o) {
  ll r = 0;
  if (vx.x == 0) {
    if (vx.y == 1)
      r = 3;
    else
      r = 1;
  } else if (vx.x == -1) {
    r = 2;
  }

  // cout << "apply " << vx << " " << r << endl;

  rotate(p, r);
  if ((vx & vy) < 0) {
    if (vx.x == 0) {
      rotateX(p, 0);
    } else {
      rotateY(p, 0);
    }
  }

  p += o;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Q, M, a, b;
  cin >> N;

  vector<P> plist(N);

  P o, vx, vy, p;
  vx.x = 1;
  vy.y = 1;

  REP(i, N) { cin >> plist[i].x >> plist[i].y; }
  cin >> M;

  vector<P> olist(M + 1);
  vector<P> vxlist(M + 1);
  vector<P> vylist(M + 1);

  vxlist[0] = vx;
  vylist[0] = vy;

  REP(i, M) {
    cin >> a;
    if (a == 1 || a == 2) {
      ll r = a == 1 ? 1 : -1;
      rotate(o, r);
      rotate(vx, r);
      rotate(vy, r);
    } else {
      cin >> b;
      if (a == 3) {
        rotateX(o, b);
        rotateX(vx, b);
        rotateX(vy, b);
      } else {
        rotateY(o, b);
        rotateY(vx, b);
        rotateY(vy, b);
      }
    }

    olist[i + 1] = o;
    vxlist[i + 1] = vx - o;
    vylist[i + 1] = vy - o;

    // cout << (i + 1) << " o " << o << " vx " << (vx - o) << " vy " << (vy - o)
    //     << endl;
  }

  cin >> Q;

  REP(i, Q) {
    cin >> a >> b;
    o = olist[a];
    vx = vxlist[a];
    vy = vylist[a];
    p = plist[b - 1];

    apply(p, vx, vy, o);
    cout << p << endl;
  }
}