#include <bits/stdc++.h>
inline int read() {
  char c = getchar();
  int x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
const int N = 1e5 + 5;
int n, a[N], ban[N], f[N], pre[N];
std::vector<int> q[1000], res;
std::vector<std::vector<int>> ans;
void solve(int k) {
  int len = 0;
  q[0].clear();
  q[0].push_back(0);
  for (int i = 1; i <= n; ++i)
    if (!ban[a[i]]) {
      int l = 0, r = len + 1, mid;
      while (l < r) {
        mid = (l + r) >> 1;
        if (a[i] > q[mid].back())
          l = mid + 1;
        else
          r = mid;
      }
      if (l == len + 1) q[++len].clear();
      q[l].push_back(a[i]);
      f[a[i]] = l;
      pre[a[i]] = q[l - 1].back();
    }
  if (len >= k) {
    int pos = -1;
    for (int i = 1; i <= n; ++i)
      if (!ban[i]) {
        if (f[i] == len) {
          pos = i;
          break;
        }
      }
    res.clear();
    for (int v = pos; v; v = pre[v]) res.push_back(v), ban[v] = 1;
    std::reverse(res.begin(), res.end());
    ans.push_back(res);
    solve(k - 1);
  } else {
    for (int i = 1; i <= len; ++i) ans.push_back(q[i]);
  }
}
int main() {
  int T = read();
  while (T--) {
    n = read();
    for (int i = 1; i <= n; ++i) a[i] = read(), ban[i] = 0;
    int k = 1;
    while (k * (k + 1) / 2 <= n) ++k;
    ans.clear();
    solve(k);
    printf("%d\n", (int)ans.size());
    for (auto x : ans) {
      printf("%d ", (int)x.size());
      for (auto v : x) printf("%d ", v);
      puts("");
    }
  }
  return 0;
}
