#include <bits/stdc++.h>
inline int in() {
  int k = 0;
  char ch = getchar();
  bool p = 1;
  while (ch < '-') ch = getchar();
  if (ch == '-') ch = getchar(), p = 0;
  while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
  return p ? k : -k;
}
using std::set;
using std::vector;
const int N = 1e5 + 5;
vector<int> ans[N];
int f[N], dp[N], st[N], top, o[N];
int calc(vector<int> a, int n) {
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (!d || a[i] > st[d]) {
      st[++d] = a[i];
    } else {
      *(std::lower_bound(st + 1, st + d + 1, a[i])) = a[i];
    }
    dp[i] = std::lower_bound(st + 1, st + d + 1, a[i]) - st;
  }
  return d;
}
struct node {
  int id, d;
  node() {}
  node(int a, int b) : id(a), d(b) {}
};
inline bool operator<(const node &a, const node &b) { return a.d < b.d; }
set<node> cx;
inline void New(int x) { ans[++top].push_back(x), cx.insert(node(top, x)); }
void solve(vector<int> a, int n) {
  if (!n) {
    return;
  }
  memset(dp, 0, n << 2);
  memset(st, 0, n << 2);
  int LIS = calc(a, n);
  if (LIS > f[n]) {
    ans[++top].resize(LIS + 1);
    int k = 0;
    for (int i = n - 1; ~i; i--) {
      if (dp[i] + k == LIS && (!k || a[i] < ans[top][k])) {
        o[ans[top][++k] = a[i]] = 1;
      }
    }
    std::reverse(ans[top].begin(), ans[top].end());
    ans[top].resize(k);
    for (vector<int>::iterator it = a.begin(); it != a.end();) {
      if (o[*it]) {
        it = a.erase(it);
      } else {
        it++;
      }
    }
    for (int i = 0; i < k; i++) {
      o[ans[top][i]] = 0;
    }
    return solve(a, n - k);
  }
  New(a[0]);
  set<node>::iterator it;
  int t;
  for (int i = 1; i < n; i++) {
    it = cx.upper_bound(node(0, a[i]));
    if (it == cx.end()) {
      New(a[i]);
    } else {
      t = it->id, cx.erase(it);
      ans[t].push_back(a[i]), cx.insert(node(t, a[i]));
    }
  }
}
inline void work() {
  int n = in();
  vector<int> a(n);
  cx.clear();
  for (int i = 0; i < n; i++) {
    a[i] = in();
  }
  top = 0;
  solve(a, n);
  printf("%d\n", top);
  for (int i = 1; i <= top; i++, puts("")) {
    printf("%d ", ans[i].size());
    for (int x : ans[i]) {
      printf("%d ", x);
    }
    vector<int>().swap(ans[i]);
  }
}
int main() {
  for (int i = 1; i * (i + 1) / 2 < N; i++) {
    f[i * (i + 1) / 2] = 1;
  }
  for (int i = 2; i < N; i++) {
    f[i] += f[i - 1];
  }
  for (int t = in(); t; t--) {
    work();
  }
  return 0;
}
