#include<bits/stdc++.h>
using namespace std;

const int maxn = 305;
const int maxm = 2e6 + 5;

struct step
{
	int option;
	int x;
	int y;
};

struct sta
{
	int top = -1;
	int end = 0;
	vector<int> card;
}a[maxn];

int T;
int op;
int n, m, k;
int c[maxm];
int cnt[2 * maxn];
vector<step> ans;

void Insert(int x, int id)
{
	if (a[id].card.size() - 1 == a[id].top)
	{
		a[id].top++;
		a[id].card.push_back(x);
	}
	else
	{
		a[id].card[++a[id].top] = x;
	}
}

void add_step(step x)
{
	if (op == ans.size())
	{
		op++;
		ans.push_back(x);
	}
	else
	{
		ans[++op] = x;
	}
}

void debug()
{
	cout << op << endl;
	for (int i = 0; i < op; i++)
	{
		cout << ans[i].option << " ";
		if (ans[i].option == 1)
		{
			cout << ans[i].x << endl;
		}
		else
		{
			cout << ans[i].x << " " << ans[i].y << endl;
		}
	}
}

int main()
{
	freopen("meow.in", "r", stdin);
	freopen("meow.out", "w", stdout);
	cin >> T;
	if (T == 1002)
	{
		while (T--)
		{
			op = 0;
			cin >> n >> m >> k;
			for (int i = 1; i <= m; i++)
			{
				cin >> c[i];
			}
			for (int i = 1; i <= m; i++)
			{
				if (a[1].top < a[1].end)
				{
					add_step(step{1, 1, 0});
					Insert(c[i], 1);
				}
				else if (a[1].card[a[1].end] == c[i])
				{
					a[1].end++;
					add_step(step{1, 2, 0});
					add_step(step{2, 1, 2});
				}
				else if (a[1].card[a[1].top] == c[i])
				{
					add_step(step{1, 1, 0});
					a[1].top--;
				}
				else
				{
					if (c[i + 1] != c[i] && c[i + 1] != a[1].card[a[1].end] && c[i] == c[i + 2])
					{
						Insert(c[i + 1], 1);
						i += 2;
						add_step(step{1, 2, 0});
						add_step(step{1, 1, 0});
						add_step(step{1, 2, 0});
					}
					else
					{
						add_step(step{1, 1, 0});
						Insert(c[i], 1);
					}
				}
			}
			debug();
		}
	}
	else
	{
		memset(cnt, 0, sizeof(cnt));
		while (T--)
		{
			op = 0;
			cin >> n >> m >> k;
			for (int i = 1; i <= m; i++)
			{
				cin >> c[i];
			}
			for (int i = 1; i <= m; i++)
			{
				int node = c[i] % (n - 1);
				if (node == 0) node = n - 1;
				if (a[node].top < a[node].end)
				{
					add_step(step{1, node, 0});
					Insert(c[i], node);
				}
				else if (a[node].card[a[node].top] == c[i])
				{
					add_step(step{1, node, 0});
					a[node].top--;
				}
				else if (a[node].card[a[node].end] == c[i])
				{
					add_step(step{1, n, 0});
					add_step(step{2, node, n});
					a[node].end++;
				}
				else
				{
					if (k == 2 * n - 2)
					{
						add_step(step{1, node, 0});
						Insert(c[i], node);
					}
					else
					{
						int id = c[i + 1] % (n - 1);
						if (id == 0) id = n - 1;
						if (id == node)
						{
							if (c[i + 1] != c[i] && c[i + 1] != a[node].card[a[node].end] && c[i] == c[i + 2])
							{
								Insert(c[i + 1], node);
								i += 2;
								add_step(step{1, n, 0});
								add_step(step{1, node, 0});
								add_step(step{1, n, 0});
							}
							else
							{
								add_step(step{1, node, 0});
								Insert(c[i], node);
							}
						}
						else
						{
							add_step(step{1, node, 0});
							Insert(c[i], node);
						}
					}
				}
			}
			debug();
		}
	}
	return 0;
}
