#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define int long long

using namespace std;

const int M = 2e6 + 10;

int T, n, m, k, a[M];
struct St0ck {
	int head, cnt, tail;
} st[301];

int arr[101][M / 3], cnt[101];

// n stock num
// m card num
// k card pattern

// 1 2 3 1 2 3
// 1 2 3 2 1 3
// 1 2 3 1 3 2
// 1 2 3 3 1 2
// 1 2 3 2 3 1
// 1 2 3 3 2 1

inline void solve ()
{
	scanf ("%lld %lld %lld", &n, &m, &k);
	for (int i = 1; i <= m; ++ i)
		scanf ("%lld", &a[i]);
	for (int i = 1; i <= m; ++ i)
	{
		
		arr[ceil (a[i] / 3)][++ cnt[ceil (a[i] / 3)]] = a[i];
	}
	for (int i = 1; i <= k / 3 + 1; i ++)
	{
		for (int j = 1; j <= cnt[i]; ++ i)
		{
			int pos1, pos2;
			if (arr[i][j] % 3 == 0)
			{
				pos2 = arr[i][j] / 3 * 2;
				pos1 = pos2 - 1;
			}
			else
				pos1 = 2 * (arr[i][j] / 3) + 1, pos2 = pos1 + 1;
			if (st[pos1].cnt + st[pos2].cnt == 0)
			{
				cout << 1 << " " << arr[i][j] << endl;
				st[pos1].cnt = 1;
				st[pos1].tail = arr[i][j];
				st[pos1].head = arr[i][j];
			}
			else if (st[pos1].cnt + st[pos2].cnt == 1)
			{
				if (st[pos1].head == arr[i][j] || st[pos2].tail == arr[i][j])
				{
					if (st[pos1].head == arr[i][j])
						cout << 1 << " " << pos1 << endl;
					else
						cout << 1 << " " << pos2 << endl;
				}
				else
				{
					if (st[pos1].cnt == 1)
					cout << 1 << " " << pos1 << endl;
					else
						cout << 1 << " " << pos2 << endl;
				}
			} 
			else if (st[pos1].tail)
		}
	}
	return ;
}

signed main ()
{
	freopen ("meow.in", "r", stdin);
	freopen ("meow.out", "w", stdout);
	cin.tie(0);
	scanf ("%lld", &T);
	while (T --)
		solve ();
	
	return 0;
}