#include "testlib.h"
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>


typedef long long ll;
typedef long double ld;

using namespace std;
const int MAXN = 100000;
const int MAXM = 1000000000;
const int MAXQ = 100000;

int main(int , char **argv) {
	registerValidation();
	int gr = atoi(argv[1]);
	inf.readInt(gr, gr, "group");
	inf.readSpace();
	int n = inf.readInt(1, MAXN, "n");
	inf.readSpace();
	int m = inf.readInt(0, MAXM, "m");
	ensure(gr != 1 || (n <= 10000));
	ensure(gr != 2 || ((ll)n * m <= 1000000));
	ensure((gr != 2 && gr != 3 && gr != 3) || m <= 100000);
	inf.readEoln();
	for (int i = 0; i < n; ++i) {
		inf.readInt(0, m, "h[i]");
		if (i == n - 1)
			inf.readEoln();
		else
			inf.readSpace();
	}
	int q = inf.readInt(1, MAXQ);
	inf.readEoln();
	for (int i = 0; i < q; ++i) {
		int x;
		x = inf.readInt(1, n, "p[i]");
		ensure((gr != 2 && gr != 4) || x == i + 1);
		ensure(gr != 3 || x == (n - i));
		inf.readSpace();
		inf.readInt(0, m,  "a[i]");
		inf.readEoln();
	}
	inf.readEof();

	return 0;
}


