#include <algorithm>
#include <cstdio>
#include <deque>
using namespace std;
void read(int &x) {
char c = getchar();
int v = 0, f = 1;
while (c < '0' || '9' < c) {
if (c == '-')
f = -1;
c = getchar();
}
while ('0' <= c && c <= '9') {
v = (v << 1) + (v << 3) + (c ^ 48);
c = getchar();
}
x = v * f;
}
const int N = 300 + 5, M = 2e6 + 5;
int T, n, m, k, a[M], now;
int ans[M][2], op = 0;
deque<int> q[N];
int sp = 1, s[N << 1], t[N << 1];
void init0() {
// freopen("meow.in", "r", stdin);
// freopen("meow.out", "w", stdout);
read(T);
}
void init() {
op = 0, sp = now = 1;
read(n), read(m), read(k);
for (int i = 1; i <= n; i++)
q[i].clear();
for (int i = 1; i <= k; i++)
t[i] = 0;
for (int i = 1; i <= m; i++)
read(a[i]);
}
void change(int x, int y) {
op++;
ans[op][0] = x;
ans[op][1] = y;
if (y) {
int z = q[x].front();
q[x].pop_front();
q[y].pop_front();
t[z] -= 2;
} else {
if (q[x].empty() || q[x].back() != a[now]) {
q[x].push_back(a[now]);
s[a[now]] = x;
t[a[now]]++;
} else {
q[x].pop_back();
t[a[now]]--;
}
now++;
}
}
bool check1() {
int x = s[a[now]], y = t[a[now]];
if (y) {
if (q[x].back() == a[now]) {
change(x, 0);
return true;
} else if (q[x].front() == a[now]) {
change(sp, 0);
change(sp, x);
return true;
}
} else {
for (int i = 1; i <= n; i++) {
if (i == sp)
continue;
if (q[i].size() < 2) {
change(i, 0);
return true;
}
}
}
return false;
}
void check2() {
int p = now, x = m, y = -1;
for (int i = p + 1; i <= m; i++) {
if (a[i] == a[p]) {
x = i;
break;
} else if (a[i] == q[s[a[i]]].front()) {
x = i;
y = 0;
break;
}
}
if (y == -1) {
while (now <= x) {
if (a[now] == a[p])
change(sp, 0);
else
change(s[a[now]], 0);
}
return;
}
for (int i = p + 1; i < x; i++) {
if (a[i] == q[s[a[x]]].back())
y++;
}
if (y & 1) {
change(sp, 0);
sp = s[a[x]];
while (now <= x)
change(s[a[now]], 0);
} else {
change(s[a[x]], 0);
while (now < x)
change(s[a[now]], 0);
int z = s[a[x]];
change(sp, 0);
change(sp, z);
}
}
void solve() {
while (now <= m) {
if (!check1())
check2();
}
printf("%d\n", op);
for (int i = 1; i <= op; i++) {
if (!ans[i][1])
printf("1 %d\n", ans[i][0]);
else
printf("2 %d %d\n", ans[i][0], ans[i][1]);
}
}
int main() {
init0();
while (T--) {
init();
solve();
}
return 0;
}
WA on #20,并且本地和OJ结果不同