#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int T, n, m, k;
int a[N];
int sta[100][N], head[100], tail[100];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("meow.in", "r", stdin);
	cin >> T;
	freopen("asdf.out", "w", stdout);
	while(T --)
	{
		cin >> n >> m >> k;
		for (int i = 1; i <= m; ++ i) cin >> a[i];
		freopen("meow.ans", "r", stdin);
		int tot, now = 0;
		cin >> tot;
		for (int i = 1; i <= tot; ++ i)
		{
			int op, x, y;
			cin >> op;
			if(op == 1)
			{
				cin >> x;
				++ now;
				if(head[x] != tail[x] && sta[x][tail[x]] == a[now]) -- tail[x];
				else sta[x][++ tail[x]] = a[now];
			}
			else
			{
				cin >> x >> y;
				++ head[x], ++ head[y];
				cout << i << " " << sta[x][head[x]] << "\n";
			}
//			for (int i = 1; i <= n; ++ i)
//			{
//				for (int j = head[i] + 1; j <= tail[i] && j <= head[i] + 10; ++ j)
//				cout << sta[i][j] << " ";
//				cout << "\n";
//			}
//			cout << "\n";
		}
	}
}