#include <bits/stdc++.h>
using namespace std;
int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
const int N = 1e5 + 5;
int n, pn;
int a[N];
int f[N], bit[N];
void add(int x, int v) {
  for (; x <= pn; x += x & -x) bit[x] = max(bit[x], v);
}
int query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret = max(ret, bit[x]);
  return ret;
}
bool bz[N];
int m;
vector<int> key[N];
void solve(int n, int *a) {
  if (!n) return;
  for (int i = 1; i <= pn; i++) bit[i] = 0;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    bz[i] = 0;
    f[i] = query(a[i] - 1) + 1;
    add(a[i], f[i]);
    mx = max(mx, f[i]);
  }
  int k = sqrt(n * 2);
  while (k * (k + 1) / 2 < n) k++;
  while (k * (k - 1) / 2 >= n) k--;
  if (mx >= k) {
    int v = pn + 1, now = mx;
    m++;
    for (int i = n; i >= 1; i--)
      if (f[i] == now && a[i] < v) {
        v = a[i];
        key[m].push_back(a[i]);
        now--;
        bz[i] = 1;
      }
    reverse(key[m].begin(), key[m].end());
    int n_ = 0;
    for (int i = 1; i <= n; i++)
      if (!bz[i]) a[++n_] = a[i];
    n = n_;
    solve(n, a);
  } else {
    for (int i = 1; i <= n; i++) key[m + f[i]].push_back(a[i]);
    m += mx;
  }
}
void solve() {
  n = get();
  for (int i = 1; i <= n; i++) a[i] = get();
  pn = n;
  m = 0;
  for (int i = 1; i <= n; i++) key[i].clear();
  solve(n, a);
  printf("%d\n", m);
  for (int i = 1; i <= m; i++) {
    printf("%d", key[i].size());
    for (auto x : key[i]) printf(" %d", x);
    putchar('\n');
  }
}
int main() {
  for (int _ = get(); _; _--) solve();
  return 0;
}
