#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, m, n, k, t, tt, l, r, a1, ans[100007], q[100007], w[100007],
    w1[100007];
int v[100007], la[100007], num[1007];
vector<int> ff[100007];
int main() {
  scanf("%d", &tt);
  for (int i = 1; i <= 1000; i++) num[i] = (i + 1) * i / 2;
  for (int ii = 1; ii <= tt; ii++) {
    scanf("%d", &a);
    a1 = 0;
    while (num[a1 + 1] <= a) a1++;
    t = 0;
    e = 0;
    for (int i = 1; i <= a; i++) scanf("%d", &q[i]);
    while (a) {
      b = 0;
      for (int i = 1; i <= a; i++) la[q[i]] = 0;
      for (int i = 1; i <= a; i++) ff[i].clear();
      for (int i = 1; i <= a; i++) {
        l = 1;
        r = b + 1;
        while (l < r) {
          int m = (l + r) / 2;
          if (w1[m] > q[i])
            r = m;
          else
            l = m + 1;
        }
        w1[l] = q[i];
        ff[l].push_back(q[i]);
        if (l == b + 1) b++;
        if (l > 1) la[q[i]] = w1[l - 1];
      }
      if (b <= a1 - e) {
        for (int i = 1; i <= b; i++) {
          for (int j = 1; j <= ff[i].size(); j++) ans[++t] = ff[i][j - 1];
          v[++e] = ff[i].size();
        }
        break;
      }
      d = 1;
      int a2 = 0;
      for (int i = b - 1; i >= 1; i--) w1[i] = la[w1[i + 1]];
      w1[b + 1] = 0;
      for (int i = 1; i <= a; i++)
        if (q[i] == w1[d])
          ans[++t] = q[i], d++;
        else
          w[++a2] = q[i];
      a = a2;
      for (int i = 1; i <= a; i++) q[i] = w[i];
      v[++e] = b;
    }
    d = 0;
    printf("%d\n", e);
    for (int i = 1; i <= e; i++) {
      printf("%d", v[i]);
      for (int j = d + 1; j <= d + v[i]; j++) printf(" %d", ans[j]);
      d += v[i];
      printf("\n");
    }
  }
  return 0;
}
