#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

vector<vector<ll>> matsum(vector<vector<ll>> A, vector<vector<ll>> B) {
  if (A.size()!=B.size()||A[0].size()!=B[0].size()) return {{}};
  ll h = A.size(), w = A[0].size();
  vector<vector<ll>> result(h,vector<ll>(w,0));
  rep(i,h) rep(j,w) result[i][j] = (A[i][j]+B[i][j])%MOD;
  return result;
}

vector<vector<ll>> matdiff(vector<vector<ll>> A, vector<vector<ll>> B) {
  if (A.size()!=B.size()||A[0].size()!=B[0].size()) return {{}};
  ll h = A.size(), w = A[0].size();
  vector<vector<ll>> result(h,vector<ll>(w,0));
  rep(i,h) rep(j,w) result[i][j] = (MOD+(A[i][j]-B[i][j])%MOD)%MOD;
  return result;
}

vector<vector<ll>> matdot(vector<vector<ll>> A, vector<vector<ll>> B) {
  if (A[0].size()!=B.size()) return {{}};
  ll h = A.size(), w = B[0].size(), x = A[0].size();
  vector<vector<ll>> result(h,vector<ll>(w,0));
  rep(i,h) rep(j,w) rep(k,x) result[i][j] = (result[i][j] + A[i][k]*B[k][j]);
  return result;
}

vector<vector<ll>> matpow(vector<vector<ll>> A, ll n) {
  if (A.size()!=A[0].size()) return {{}};
  int N = A.size();
  vector<vector<ll>> result(N,vector<ll>(N,0)), now;
  copy(all(A),back_inserter(now));
  rep(i,N) result[i][i] = 1;
  ll p2 = 1; 
  while (n>=p2) {
    if (n&p2) result = matdot(result,now);
    now = matdot(now,now); p2 *= 2;
  }
  return result;
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  ll N; cin >> N;
  ll X[N], Y[N]; rep(i,N) cin >> X[i] >> Y[i];
  ll M; cin >> M;
  ll op[M][2] = {}; rep(i,M) { cin >> op[i][0]; if (op[i][0]>=3) cin >> op[i][1]; }
  ll Q; cin >> Q;
  ll A[Q], B[Q]; rep(i,Q) { cin >> A[i] >> B[i]; B[i]--; }

  vector<vector<ll>> ope = { {1,0,0}, {0,1,0}, {0,0,1} };
  vector<vector<vector<ll>>> opmat(M+1); opmat[0] = ope;
  rep(i,M) {
    vector<vector<ll>> mulmat;
    if (op[i][0]==1) {
      mulmat = {
        {0,1,0},
        {-1,0,0},
        {0,0,1}
      };
    }
    else if (op[i][0]==2) {
      mulmat = {
        {0,-1,0},
        {1,0,0},
        {0,0,1}
      };
    }
    else if (op[i][0]==3) {
      mulmat = {
        {-1,0,2*op[i][1]},
        {0,1,0},
        {0,0,1}
      };
    }
    else if (op[i][0]==4) {
      mulmat = {
        {1,0,0},
        {0,-1,2*op[i][1]},
        {0,0,1}
      };
    }
    opmat[i+1] = matdot(mulmat,opmat[i]);
  }

  // rep(i,M+1) {
  //   for (auto x: opmat[i]) debug(all(x));
  //   cout << endl;
  // }

  rep(i,Q) {
    vector<vector<ll>> resmat = matdot(opmat[A[i]],{{X[B[i]]},{Y[B[i]]},{1}});
    cout << resmat[0][0] << " " << resmat[1][0] << endl;
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Union-Find
 * @docs docs/union-find.md
 */
struct UnionFind {
  vector< int > data;

  UnionFind() = default;

  explicit UnionFind(size_t sz) : data(sz, -1) {}

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    //if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return data[k] = find(data[k]);
  }

  int size(int k) {
    return -data[find(k)];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
};


int main() {
  int N, Q;
  cin >> N >> Q;
  vector< int > C(N);
  cin >> C;
  for(auto &c : C) --c;
  UnionFind uf(N);
  vector< map< int, int > > mp(N);
  for(int i = 0; i < N; i++) mp[i][C[i]]++;
  while(Q--) {
    int t, a, b;
    cin >> t >> a >> b;
    --a, --b;
    if(t == 1) {
      int p = uf.find(a);
      int q = uf.find(b);
      if(p == q) continue;
      if(mp[p].size() < mp[q].size()) {
        swap(p, q);
      }
      for(auto &z : mp[q]) mp[p][z.first] += z.second;
      mp[q].clear();
      uf.unite(p, q);
    } else {
      cout << mp[uf.find(a)][b] << "\n";
    }
  }
}


