#include <bits/stdc++.h>
using namespace std;
const int maxN = 100001;
int tops[maxN], T[maxN], parent[maxN];
vector<int> lis[maxN];
vector<vector<int> > res;
bool used[maxN];
void normal(int n) {
  int j = 0;
  for (int i = 1; j <= n; i++) {
    if (!used[T[i]]) continue;
    j = max(j, i);
    while (j <= n and used[T[j]]) j++;
    if (j <= n) swap(T[i], T[j]);
  }
}
int cntlis(int n) {
  fill(tops + 1, tops + n + 1, maxN);
  for (int i = (0); (i) < (n + 1); (i)++) lis[i].resize(0);
  for (int i = (1); (i) < (n + 1); (i)++) {
    int j = lower_bound(tops, tops + n + 1, T[i]) - tops;
    parent[T[i]] = tops[j - 1];
    lis[j].push_back(tops[j] = T[i]);
  }
  int s = n;
  while (tops[s] == maxN) s--;
  return s;
}
int getk(int n) {
  int k = 1;
  while ((k + 1) * (k + 2) / 2 <= n) k++;
  return k;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = (1); (i) < (n + 1); (i)++) scanf("%d", T + i);
    res.resize(0);
    fill(used, used + n + 1, false);
    int s;
    while ((s = cntlis(n)) > getk(n)) {
      res.push_back({});
      for (int v = tops[s]; v != 0; v = parent[v])
        res.back().push_back(v), used[v] = true;
      reverse((res.back()).begin(), (res.back()).end());
      normal(n);
      n -= res.back().size();
    }
    for (int i = (1); (i) < (s + 1); (i)++) res.push_back(lis[i]);
    printf("%d\n", (int)res.size());
    for (int i = (0); (i) < (res.size()); (i)++) {
      printf("%d ", (int)res[i].size());
      for (int v : res[i]) printf("%d ", v);
      printf("\n");
    }
  }
  return 0;
}
