/*---------------------
  auther: nomonick
  contest: NOIP
  task name: meow
  code time: 2022/11/26 10:04
  E(T2): ???? // WA .all is wrong. only 5 mins, QwQ.
  rp++
---------------------*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int SIZE = (int)2e6 + 50;
const int mod = 998244353;

inline int read()
{
	int x = 0,f = 1;
	char ch = getchar();
	while (ch < '0' or ch > '9')
	{
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while ('0' <= ch and ch <= '9')
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return f * x;
}

inline void write(int x)
{
	if (x < 0) putchar('-'), x *= -1;
	if (x > 9) write(x / 10), putchar((x % 10) + '0');
	else putchar(x % 10 + '0');
}

int t,n,m,k,tot,sum;
int num[SIZE];
priority_queue<int,vector<int>,greater<int> > que;
deque<int> wait;
std::vector<pair<int, pair<int,int> > > ans;
std::map<int,int> stc;

inline void solution2()
{
	if (wait.empty()) return;
	int x = wait.front();
	while (stc[num[x]] > 1 and sum)
	{
		ans.push_back(make_pair(2,make_pair(1,stc[num[x]])));
		que.push(stc[num[x]]); stc[num[x]] = 0; sum -= 2; tot++;
		wait.pop_front(); 
		if (wait.empty()) {que.push(1); break;}
		x = wait.front();
	}
}

inline void solve()
{
	n = read(); m = read(); k = read(); sum = m; tot = n;
	for (int i = 1; i <= m; ++i) num[i] = read();
	ans.clear(); while (!que.empty()) que.pop();
	for (int i = 1; i <= n; ++i) que.push(i);
	for (int i = 1; i <= m and sum; ++i)
	{
		if (not wait.empty())
		{
			int x = wait.front();
			while (stc[num[x]] > 1 and sum)
			{
				ans.push_back(make_pair(2,make_pair(1,stc[num[x]])));
				que.push(stc[num[x]]); stc[num[x]] = 0; sum -= 2; tot++;
				wait.pop_front(); 
				if (wait.empty()) {que.push(1); break;}
				x = wait.front();
			}
		}
		if (tot)
		{
			if (stc[num[i]] > 1)
			{
				ans.push_back(make_pair(1,make_pair(stc[num[i]],-1)));
				que.push(stc[num[i]]); stc[num[i]] = 0; sum -= 2; tot++;
				solution2();continue;
			}
			if (!wait.empty() and wait.back() == num[i])
			{
				ans.push_back(make_pair(1,make_pair(1,-1)));
				wait.pop_back(); if (wait.empty()) que.push(1), tot++; sum -= 2;
				solution2();continue;
			}
			ans.push_back(make_pair(1,make_pair(que.top(),-1)));
			if (que.top() == 1) wait.push_back(num[i]);
			else stc[num[i]] = que.top(); 
			que.pop(); tot--;
			solution2();continue;
		}
		if (stc[num[i]] > 1)
		{
			ans.push_back(make_pair(1,make_pair(stc[num[i]],-1)));
			que.push(stc[num[i]]); stc[num[i]] = 0; sum -= 2; tot++;
			solution2();continue;
		}
		if (!wait.empty() and wait.back() == num[i])
		{
			ans.push_back(make_pair(1,make_pair(1,-1)));
			wait.pop_back(); if (wait.empty()) que.push(1), tot++; sum -= 2;
			solution2();continue;
		}
		if (wait.empty()) continue;
		int x = wait.front();
		while (stc[num[x]] > 1 and sum)
		{
			ans.push_back(make_pair(2,make_pair(1,stc[num[x]])));
			que.push(stc[num[x]]); stc[num[x]] = 0; sum -= 2; tot++;
			wait.pop_front(); 
			if (wait.empty()) {que.push(1); break;}
			x = wait.front();
		}
		ans.push_back(make_pair(1,make_pair(1,-1)));
		wait.push_back(num[i]);
	}
	if (sum)
	{
		int x = wait.front();
		while (stc[num[x]] > 1)
		{
			ans.push_back(make_pair(2,make_pair(1,stc[num[x]])));
			que.push(stc[num[x]]); stc[num[x]] = 0; sum -= 2; tot++;
			wait.pop_front(); 
			if (wait.empty()) {que.push(1); break;}
			x = wait.front();
		}
	}
	write(ans.size()); puts("");
	for (auto x : ans)
	{
		write(x.first); putchar(' ');
		if (x.first == 1) write(x.second.first);
		else write(x.second.first), putchar(' '), write(x.second.second);
		puts("");
	}
}

signed main()
{
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	t = read();
	for (int T = t; T; --T) solve();
	return 0;
}
