#include <bits/stdc++.h>
using namespace std;
inline long long qr() {
  long long x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())
    ;
  return x * f;
}
const int N = 100010;
int n, k, a[N], res;
int s[N], top, b[N], c[N];
int lt[N], nt[N];
vector<int> ans[500];
int LIS() {
  for (int i = 1; i <= top; ++i) b[i] = lt[i] = nt[i] = 0;
  s[top = 1] = 1e5 + 1;
  for (int i = 1; i <= n; ++i) {
    int p = upper_bound(s + 1, s + 1 + top, a[i]) - s;
    s[p] = a[i];
    lt[i] = b[p];
    b[p] = i;
    nt[i] = b[p - 1];
    if (p == top) s[++top] = 1e5 + 1;
  }
  return top - 1;
}
void Find(int x) {
  ans[++res].clear();
  for (int i = b[x]; i; i = nt[i]) ans[res].push_back(a[i]), a[i] = -1;
}
void Div(int n) {
  for (int i = 1; i <= n; ++i) {
    ans[++res].clear();
    for (int j = b[i]; j; j = lt[j]) ans[res].push_back(a[j]);
  }
}
int main() {
  int kase = qr();
  while (kase--) {
    n = qr();
    res = 0;
    for (int i = 1; i <= n; ++i) a[i] = qr();
    while (n) {
      int k = LIS();
      if (1LL * k * (k + 1) > 2 * n)
        Find(k);
      else {
        Div(k);
        break;
      }
      int ct = 0;
      for (int i = 1; i <= n; ++i)
        if (a[i] != -1) a[++ct] = a[i];
      n = ct;
    }
    printf("%d\n", res);
    for (int i = 1; i <= res; ++i) {
      int l = ans[i].size();
      printf("%d ", l);
      for (int j = l - 1; j >= 0; --j) printf("%d ", ans[i][j]);
      puts("");
    }
  }
  return 0;
}
