#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define PNAME "meow"

#ifdef LOCAL_TEST
#define FNAME "meow_test1"
#else
#define FNAME PNAME
#endif

const int max_n = 300, max_k = 2 * max_n - 1, max_m = 2000000;

bool ty[max_m];
int a[max_m], op[max_m * 2][3], lstt[max_k], opc;
vector<int> stk[max_n];

signed main()
{
	freopen(FNAME ".in", "r", stdin);
	freopen(FNAME ".out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int cas, n, m, k;
	
	cin >> cas;
	while (cas--)
	{
		opc = 0;
		
		cin >> n >> m >> k;
		for (int i = 0; i < m; i++)
			cin >> a[i];
		for (int i = 0; i < n; i++)
			stk[i].clear();
		
		if (k == 2 * n - 2)
		{
			for (int i = 0; i < m; i++)
			{
				a[i]--;
				if (!stk[a[i] / 2].empty() && a[stk[a[i] / 2].back()] == a[i])
				{
					ty[stk[a[i] / 2].back()] = false;
					stk[a[i] / 2].pop_back();
				}
				else
					ty[i] = true, stk[a[i] / 2].push_back(i);
			}
			for (int i = 0; i < n; i++)
				stk[i].clear();
			
			fill(lstt, lstt + k, 0);
			for (int i = 0; i < m; i++)
			{
				op[opc][0] = 1;
				if (ty[i])
				{
					if (lstt[a[i]])
					{
						op[opc][1] = a[i] / 2;
						// stk[a[i] / 2].push_back(a[i]);
					}
					else
					{
						op[opc][1] = n - 1;
						stk[n - 1].push_back(a[i]);
					}
					lstt[a[i]] ^= 1;
				}
				else
					op[opc][1] = a[i] / 2;
				opc++;
			}
			
			for (int ax : stk[n - 1])
			{
				op[opc][0] = 2;
				op[opc][1] = n - 1;
				op[opc][2] = ax / 2;
				opc++;
			}
		}
		else if (n == 2)
		{
			auto fndnxt = [&](int x, int v) {
				for (int i = x + 1; i < n; i++)
					if (a[i] == v)
						return i;
				return n + 1;
			};
			int curv[3] = {0, 0, 0}, curc = 0;
			for (int i = 0; i < m; i++)
			{
				if (curc == 0)
				{
					curv[curc++] = a[i];
					op[opc][0] = 1, op[opc][1] = 0, opc++;
				}
				else if (curc == 1)
				{
					if (curv[0] == a[i])
					{
						op[opc][0] = 1, op[opc][1] = 0, opc++;
						curc--;
					}
					else
					{
						if (fndnxt(i, curv[0]) < fndnxt(i, a[i]))
							op[opc][0] = 1, op[opc][1] = 0, opc++, curv[2] = a[i], curc = 3;
						else
							op[opc][0] = 1, op[opc][1] = 1, opc++, curv[1] = a[i], curc = 2;
					}
				}
				else if (curc == 2)
				{
					if (curv[1] == a[i])
					{
						op[opc][0] = 1, op[opc][1] = 1, opc++;
						curc--;
					}
					else
					{
						op[opc][0] = 1, op[opc][1] = 0, opc++;
						curv[2] = a[i];
						curc = 4;
					}
				}
				else if (curc == 3)
				{
					if (curv[0] == a[i])
					{
						op[opc][0] = 1, op[opc][1] = 1, opc++;
						curv[0] = curv[2];
						curc = 1;
					}
					else if (curv[2] == a[i])
					{
						op[opc][0] = 1, op[opc][1] = 0, opc++;
						curc = 1;
					}
					else
					{
						op[opc][0] = 1, op[opc][1] = 1, opc++;
						curv[1] = a[i];
						curc = 4;
					}
				}
				else
				{
					if (curv[1] == a[i])
					{
						op[opc][0] = 1, op[opc][1] = 1, opc++;
						curc = 3;
					}
					else if (curv[2] == a[i])
					{
						op[opc][0] = 1, op[opc][1] = 0, opc++;
						curc = 2;
					}
				}
			}
		}
		
		cout << opc << "\n";
		for (int i = 0; i < opc; i++)
		{
			cout << op[i][0];
			for (int j = 0; j < op[i][0]; j++)
				cout << " " << op[i][j + 1] + 1;
			cout << "\n";
		}
	}
	
	return 0;
}