#include <bits/stdc++.h>
using namespace std;
vector<int> ans[5000];
const int N = 1e5 + 5000;
int w[N], g[N], f[N], pre[N], pos[N], n, tmp[N], ban[N], T;
int calc(int n) {
  int s = 0;
  for (int i = 1;; i++) {
    s += i;
    if (s > n) return i - 1;
  }
  return 0;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", w + i);
    int ansn = 0;
    while (n) {
      int mx = calc(n);
      int len = 0;
      for (int i = 1; i <= n; i++) {
        if (w[i] > g[len]) {
          f[i] = len + 1;
          pre[i] = pos[len];
          g[++len] = w[i], pos[len] = i;
          continue;
        }
        int x = lower_bound(g + 1, g + len + 1, w[i]) - g;
        pre[i] = pos[x - 1];
        f[i] = x;
        pos[x] = i, g[x] = w[i];
      }
      if (len > mx) {
        int t, tn = 0;
        for (int i = 1; i <= n; i++) ban[i] = 0;
        for (int i = 1; i <= n; i++)
          if (f[i] == len) {
            t = i;
            break;
          }
        ++ansn;
        vector<int>().swap(ans[ansn]);
        while (t) ban[t] = 1, ans[ansn].push_back(w[t]), t = pre[t];
        reverse(ans[ansn].begin(), ans[ansn].end());
        for (int i = 1; i <= n; i++)
          if (!ban[i]) tmp[++tn] = w[i];
        for (int i = 1; i <= tn; i++) w[i] = tmp[i];
        n = tn;
        continue;
      }
      for (int i = 1; i <= len; i++) vector<int>().swap(ans[ansn + i]);
      len = 0;
      for (int i = 1; i <= n; i++) {
        if (w[i] > g[len]) {
          g[++len] = w[i];
          ans[ansn + len].push_back(w[i]);
          continue;
        }
        int x = lower_bound(g + 1, g + len + 1, w[i]) - g;
        ans[ansn + x].push_back(w[i]);
        g[x] = w[i];
      }
      ansn += len;
      break;
    }
    printf("%d\n", ansn);
    for (int i = 1; i <= ansn; i++) {
      printf("%d ", ans[i].size());
      for (int j = 0; j < ans[i].size(); j++) printf("%d ", ans[i][j]);
      puts("");
    }
  }
}
