import std.stdio;
import std.algorithm;
import std.array;
import std.math;
import std.sorting;
import std.exception;
import std.typecons;
import std.string;
const int N = 100000;
int[N] c;
int[][] q;
void chmax(ref int x, int y)
{
if (x < y)
x = y;
}
void chmin(ref int x, int y)
{
if (y < x)
x = y;
}
void main()
{
q.length = N;
foreach(i; 0 .. N)
q[i] = [];
int cas;
readf(" %d", &cas);
while (cas--)
{
int n, k;
readf(" %d %d", &n, &k);
int tp = -1, op = -1;
int[2] cc = [0, 0];
foreach(i; 0 .. k)
{
readf(" %d", &c[i]);
if (c[i] >= 2)
tp = i;
else
{
cc[c[i]]++;
if (c[i] == 1)
op = i;
}
}
if (tp != -1)
{
writeln(n - 1);
foreach(i; 1 .. n)
writeln("1 ", i + 1, " ", tp + 1);
continue;
}
int t = 0, sp = 1, psp = 1;
while (true)
{
while (t == sp * (sp - 1) / 2)
sp++;
if (t * (k - 1) + (sp - 1) * cc[1] >= n - 1)
break;
psp = sp;
t++;
}
int rq = t * (k - 1) + (sp - 1) * cc[1] - (n - 1);
if (cc[1] == 0)
sp = 1;
foreach(i; 0 .. n)
q[i].length = 0;
Pair!(int, int)[] rs;
foreach(i; 0 .. k)
{
int qc = t + (c[i] ? sp - 1 : 0);
int rd = min(rq, (psp != sp && c[i] == 1) ? 1 : 0);
rd = min(rd, qc);
if (op == i)
rd = 0;
qc -= rd;
rq -= rd;
int start = (c[i] ? 0 : sp - 1);
for (int j = start; j < sp * (sp - 1) / 2 && qc > 0; j++, qc--)
q[j] ~= i;
rs ~= Pair!(int, int)(qc, i);
}
rs.sort!((a, b) => a.a < b.a);
assert(rs[$-1].a - rs[0].a <= 1);
Tuple!(int, int, int)[] ans;
int ind = sp;
int id = 0;
foreach(i; 0 .. sp)
foreach(j; (i + 1) .. sp)
{
assert(!q[id].empty);
int x = q[id][$ - 1];
q[id].length--;
int lst = i;
foreach(y; q[id])
{
ans ~= tuple(lst, ind, y);
lst = ind;
ind++;
}
ans ~= tuple(lst, j, x);
id++;
}
while (rs[$-1].a > 0)
{
int fst = -1, lst = 0;
foreach(ref pair; rs)
{
if (pair.a > 0)
{
pair.a--;
if (fst == -1)
fst = pair.b;
else
{
ans ~= tuple(lst, ind, pair.b);
lst = ind;
ind++;
}
}
}
assert(fst != -1);
ans ~= tuple(lst, 0, fst);
}
assert(ans.length == (n - 1 + t));
writeln(ans.length);
foreach(a; ans)
writeln(a[0] + 1, " ", a[1] + 1, " ", a[2] + 1);
}
}