#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (n); ++i)
using Matrix = vector<vector<int64_t>>;

int main()
{
    int64_t n;
    cin >> n;

    vector<pair<int64_t, int64_t>> piece(n);
    for (auto &[x, y] : piece)
        cin >> x >> y;

    int64_t m;
    cin >> m;

    Matrix E({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}});
    Matrix Clockwise({{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}});
    Matrix AntiClockwise({{0, -1, 0}, {1, 0, 0}, {0, 0, 1}});

    Matrix now = E;
    vector<Matrix> MX;
    MX.emplace_back(E);

    auto matmul = [](Matrix A, Matrix B) {
        // 列ベクトルと行列積をとるのに3x3決め打ちで書いていた
        Matrix ret((int64_t)A.size(), vector<int64_t>((int64_t)B[0].size(), 0));
        rep(i, (int64_t)A.size()) rep(j, (int64_t)B[0].size()) rep(k, (int64_t)A[0].size())
            ret[i][j] += A[i][k] * B[k][j];
        return ret;
    };

    auto line_sym = [](char axis, int64_t p) {
        Matrix ret;
        if (axis == 'x')
            ret = {{-1, 0, p * 2}, {0, 1, 0}, {0, 0, 1}};
        else
            ret = {{1, 0, 0}, {0, -1, p * 2}, {0, 0, 1}};
        return ret;
    };

    while (m--)
    {
        int64_t op, p;
        cin >> op;
        if (op == 1)
        {
            now = matmul(Clockwise, now);
        }
        else if (op == 2)
        {
            now = matmul(AntiClockwise, now);
        }
        else if (op == 3)
        {
            cin >> p;
            now = matmul(line_sym('x', p), now);
        }
        else if (op == 4)
        {
            cin >> p;
            now = matmul(line_sym('y', p), now);
        }
        MX.emplace_back(now);
    }

    int64_t q;
    cin >> q;
    Matrix v;
    while (q--)
    {
        int64_t a, b;
        cin >> a >> b;
        b--;
        v = {{piece[b].first}, {piece[b].second}, {1}}; // 1を忘れてdebug
        v = matmul(MX[a], v);
        cout << v[0][0] << " "s << v[1][0] << "\n"s; // 行と列を間違えてdebug
    }
    return 0;
}
#include<cstdio>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
#define G(i,a,b,c) for(long long i=(a+c-1)/c*c;i<b;i+=c)
using namespace std;
typedef unsigned long long ull;
const int N=80,P[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
template<typename T>void read(T &x)
{
	bool neg=false;
	unsigned char c=getchar();
	for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
	for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
	if(neg)x=-x;
}
long long a,b;
int c[N];
ull ans,f[N][1<<20];
int main()
{
	read(a);read(b);++b;
	F(j,0,20)
	{
		G(k,a,b,P[j])c[k-a]|=1<<j;
	}
	f[0][(1<<20)-1]=1;
	F(i,0,b-a)F(j,0,1<<20)
	{
		if((c[i]&j)==0)f[i+1][j]=f[i][c[i]^j];
		f[i+1][j]+=f[i][j];
	}
	F(j,0,1<<20)ans+=f[b-a][j];
	printf("%llu\n",ans);
	return 0;
}
