#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::max;
using std::min;
int T, n, A[100005], tA[100005], An, f[100005], id[100005], ans;
std::vector<int> S[500];
class BIT {
  int t[100005];

 public:
  void change(int x, int v) {
    for (; x <= n; x += x & -x) t[x] = max(t[x], v);
  }
  int ask(int x) {
    int res = 0;
    for (; x; x -= x & -x) res = max(res, t[x]);
    return res;
  }
  void clear() {
    for (int i = 1; i <= n; i++) t[i] = 0;
  }
} B;
void Solve2(int n) {
  for (int i = 1; i <= n; i++) id[i] = i;
  std::sort(id + 1, id + 1 + n, [](int t1, int t2) {
    return f[t1] < f[t2] || f[t1] == f[t2] && t1 < t2;
  });
  for (int i = 1, pre = 1; i <= n; i++)
    if (f[id[i]] ^ f[id[i + 1]] || i == n) {
      ans++;
      for (int j = pre; j <= i; j++) S[ans].push_back(A[id[j]]);
      pre = i + 1;
    }
}
void Solve1(int n) {
  if (!n) return;
  int Max = 0, num = 1e9;
  B.clear();
  for (int i = 1; i <= n; i++)
    f[i] = B.ask(A[i]) + 1, B.change(A[i], f[i]), Max = max(Max, f[i]);
  if ((long long)Max * (Max + 1) <= n * 2) return Solve2(n);
  ans++, An = 0;
  for (int i = n; i; i--)
    if (A[i] < num && f[i] == Max)
      S[ans].push_back(A[i]), Max--, num = A[i];
    else
      tA[++An] = A[i];
  for (int i = 1; i <= An; i++) A[i] = tA[i];
  std::reverse(A + 1, A + 1 + An);
  std::reverse(S[ans].begin(), S[ans].end());
  Solve1(An);
}
void clear() {
  for (int i = 1; i <= ans; i++) S[i].clear();
  ans = 0;
}
int main() {
  for (scanf("%d", &T); T--; clear()) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
    Solve1(n), printf("%d\n", ans);
    for (int i = 1; i <= ans; i++) {
      printf("%d ", S[i].size());
      for (int j : S[i]) printf("%d ", j);
      puts("");
    }
  }
  return 0;
}
