#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N], f[N], t[N], T, n, F, G, c;
vector<int> ans[N];
inline void upd(int x, int y) {
  for (; x <= n; x += (x & -x)) t[x] = max(t[x], y);
}
inline int qry(int x) {
  int res = 0;
  for (; x; x -= (x & -x)) res = max(res, t[x]);
  return res;
}
void MAIN() {
  cin >> n;
  c = 0;
  for (int i = (1); i <= (n); i++) cin >> a[i], ans[i].clear();
  int rem = n, K = 0;
  while (K * (K + 1) / 2 < n) K++;
  while (rem) {
    for (int i = (1); i <= (n); i++) t[i] = 0;
    F = 0;
    for (int i = (1); i <= (n); i++)
      if (a[i]) {
        f[i] = qry(a[i] - 1) + 1;
        upd(a[i], f[i]);
        F = max(F, f[i]);
      } else
        f[i] = 0;
    if (F >= K) {
      int now = F + 1, val = n + 1;
      ++c, K--;
      vector<int> tmp;
      for (int i = (n); i >= (1); i--)
        if (f[i] == now - 1 && a[i] < val) {
          now--, val = a[i];
          tmp.push_back(a[i]), a[i] = 0;
          if (now == 1) break;
        }
      while (!tmp.empty()) {
        ans[c].push_back(tmp.back());
        tmp.pop_back();
      }
      rem -= F;
    } else {
      for (int i = (1); i <= (n); i++)
        if (a[i]) ans[c + f[i]].push_back(a[i]), a[i] = 0;
      rem = 0;
      c += F;
    }
  }
  printf("%d\n", c);
  for (int i = (1); i <= (c); i++) {
    printf("%d", (int)ans[i].size());
    for (auto x : ans[i]) printf(" %d", x);
    puts("");
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) MAIN();
  return 0;
}
