#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define read(x) for(auto& qw : (x)) cin >> qw;
#define print(x) for(auto& qw : (x)) cout << qw << " "; cout << endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

const int MAX = 1e6 + 10;

ll DP[4][MAX * 3];

void test_case(){
	int N;
	ll K;
	cin >> N >> K;

	memset(DP, 0, sizeof DP);
	DP[0][0] = 1;

	for (int times : {0,1,2}) {
		for (int j = 0; j + 1 < MAX*3; j++) {
			DP[times + 1][j + 1] += DP[times][j];
			if (j + N + 1 < 3*MAX) 
				DP[times + 1][j + N + 1] -= DP[times][j];
		}
		ll at = 0;
		for (int j = 0; j < 3*MAX; j++) {
			at += DP[times + 1][j];
			DP[times + 1][j] = at;
		}
	}

	int at = 1;
	for (int i = 0; i < 3 * MAX; i++) {
		if (DP[3][i] >= K) {
			at = i;
			break;
		}
		K -= DP[3][i];
	}

	for (int i = 1; i <= N; i++) {
		int mi = max(1, at - N - i);
		int ma = min(N, at - i - 1);
		
		if (mi > ma) continue;

		if ((ma - mi + 1) < K) {
			K -= (ma - mi + 1);
			continue;
		}

		cout << i << " " << mi + K - 1 << " " << at - i - mi - K + 1 << endl;
		break;
	}
	
}

int main(){ _

	int tt = 1;
//	cin >> tt;

	while(tt--){
		test_case();
	}

	return 0;
}

#include <bits/stdc++.h>

#define LL long long

#define ull unsigned long long

#define F(i, j, k) for(int i = j; i <= k; i++)

#define DF(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

template <typename T> inline void read(T &n) {
	T w = 1;
	n = 0;
	char ch = getchar();
	while (!isdigit(ch) && ch != EOF) {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (isdigit(ch) && ch != EOF) {
		n = (n << 3) + (n << 1) + (ch & 15);
		ch = getchar();
	}
	n *= w;
}

template <typename T> inline void write(T x) {
	T l = 0;
	ull y = 0;
	if (!x) {
		putchar(48);
		return;
	}
	if (x<0) {
		putchar('-');
		x = -x;
	}
	while (x) {
		y = y * 10 + x % 10;
		x /= 10;
		l++;
	}
	while (l) {
		putchar(y % 10 + 48);
		y /= 10;
		l--;
	}
}

template <typename T> inline void writes(T x) {
	write(x);
	putchar(' ');
}

template <typename T> inline void writeln(T x) {
	write(x);
	puts("");
}

template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; }

template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; }

const int N = 2e5 + 10;

bool chg[N];

struct wzy {
	LL x, c;
	wzy (LL X = 0,LL C = 0) {
		x = X;
		c = C;
	}
};

struct Point {
	LL x, y;
} p[N];

struct Opt {
	wzy x, y;
} opt[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n;
	read(n);
	F(i, 1, n) {
		read(p[i].x);
		read(p[i].y);
	}
	int m;
	read(m);
	opt[0].x.x = 1;
	opt[0].y.x = 1;
	chg[0] = 0;
	F(i, 1, m) {
		int op;
		LL k;
		read(op);
		if (op == 1 || op == 2) {
			opt[i].x = opt[i - 1].y; 
			opt[i].y = opt[i - 1].x;
			chg[i] = chg[i - 1] ^ 1;
		}
		else {
			opt[i].x = opt[i - 1].x; 
			opt[i].y = opt[i - 1].y; 
			chg[i] = chg[i - 1];
			read(k);
		}
		if (op == 1) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = -opt[i].y.c; }
		if (op == 2) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = -opt[i].x.c;}
		if (op == 3) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = 2 * k - opt[i].x.c; }
		if (op == 4) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = 2 * k - opt[i].y.c; }
	}
	int q;
	read(q);
	F(i, 1, q) {
		int ti, pi;
		read(ti);
		read(pi);
		LL x = p[pi].x;
		LL y = p[pi].y;
		if (chg[ti]) swap(x, y);
		writes(x * opt[ti].x.x + opt[ti].x.c);
		writeln(y * opt[ti].y.x + opt[ti].y.c);
	}
	return 0;
}

