#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//MINT
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

template<typename T>
struct UnionFind {
    vector<T> d;
    UnionFind(int n=0): d(n,-1) {}
    T find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    T size(int x) { return -d[find(x)];}
};

// POWER_MODver. N^k % MOD
ll mod_pow(ll n, ll k){
    ll res = 1;
    for(; k > 0; k >>= 1){
        if(k&1) res = (res*n)%mod;
        n = (n*n)%mod;
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> f(n);
    rep(i, 0, n){
        cin >> f[i];
        f[i]--;
    }
    UnionFind<int> uf(n);
    rep(i, 0, n) uf.unite(f[i], i);
    map<int, bool> mp;
    rep(i, 0, n) mp[uf.find(i)] = true;
    mint ans = mod_pow(2, mp.size());
    cout << ans-1 << endl;
    return 0;
}


// E - Rotate and Flip
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using ll = int64_t;
using vl = vec<ll>;
using vvl = vec<vl>;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n; cin>>n;
	vl X(n), Y(n); rep(i, n) cin>>X[i]>>Y[i];

	vec<vvl> mats = {{{1,0},{0,1},{0,0}}}; // [ex,ey,o]: op0: E, (x',y')=(x,y)

	// rep(i,mats.size()){
	// 	for(auto x:mats[i]){
	// 		cout<<"("<<x[0]<<", "<<x[1]<<"), ";
	// 	}
	// 	puts("");
	// }

	int m; cin>>m;
	rep(i, m){ // op
		int c; cin>>c;
		vvl mt = mats.back();
		vl x = mt[0], y = mt[1], o = mt[2];
		if(c == 1){
			x = {x[1], -x[0]};
			y = {y[1], -y[0]};
			o = {o[1], -o[0]};
		}
		else if(c == 2){
			x = {-x[1], x[0]};
			y = {-y[1], y[0]};
			o = {-o[1], o[0]};
		}
		else if(c == 3){
			ll p; cin>>p;
			x = {-x[0] + p*2, x[1]};
			y = {-y[0] + p*2, y[1]};
			o = {-o[0] + p*2, o[1]};
		}
		else{ // c == 4
			ll p; cin>>p;
			x = {x[0], -x[1] + p*2};
			y = {y[0], -y[1] + p*2};
			o = {o[0], -o[1] + p*2};
		}
		mt = {x, y, o};
		mats.emplace_back(mt);
	}

	int q; cin>>q;
	rep(i, q){
		int a, b; cin>>a>>b; --b;
		vvl mt = mats[a];
		vl ex = mt[0], ey = mt[1], o = mt[2];
		ll x = (ex[0]-o[0])*X[b] + (ey[0]-o[0])*Y[b] + o[0];
		ll y = (ex[1]-o[1])*X[b] + (ey[1]-o[1])*Y[b] + o[1];
		cout<< x <<" "<< y <<endl;
	}

}
