#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1e5 + 10;
int n, K, top;
int a[N], sta[N], vis[N], las[N], pre[N], f[N];
vector<int> vec[N];
int read() {
  int ret = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (isdigit(c)) ret = ret * 10 + (c ^ 48), c = getchar();
  return f ? ret : -ret;
}
int getlen() {
  for (int i = 1; i <= top; ++i) vis[i] = 0;
  sta[top = 1] = INF;
  for (int i = 1; i <= n; ++i) {
    int p = upper_bound(sta + 1, sta + top + 1, a[i]) - sta;
    sta[p] = a[i];
    las[i] = vis[p];
    vis[p] = i;
    pre[i] = vis[p - 1];
    if (p == top) sta[++top] = INF;
  }
  return top - 1;
}
void LDS(int len) {
  vec[++K].clear();
  for (int i = vis[len]; i; i = pre[i]) vec[K].push_back(a[i]);
}
void LIS(int len) {
  for (int i = 1; i <= len; ++i) {
    vec[++K].clear();
    for (int j = vis[i]; j; j = las[j]) vec[K].push_back(a[j]);
  }
}
int main() {
  int T = read();
  while (T--) {
    n = read();
    K = 0;
    for (int i = 1; i <= n; ++i) a[i] = read();
    while (n) {
      int len = getlen();
      if (n <= (long long)len * (len + 1) / 2)
        LDS(len);
      else {
        LIS(len);
        break;
      }
      int tn = n, j = len;
      n = 0;
      f[j + 1] = 0;
      for (int i = vis[len]; i; i = pre[i]) f[j--] = a[i];
      ++j;
      for (int i = 1; i <= tn; ++i)
        if (a[i] ^ f[j])
          a[++n] = a[i];
        else
          ++j;
    }
    printf("%d\n", K);
    for (int i = 1; i <= K; ++i) {
      printf("%d ", (int)vec[i].size());
      reverse(vec[i].begin(), vec[i].end());
      for (int j = 0; j < (int)vec[i].size(); ++j) printf("%d ", vec[i][j]);
      puts("");
    }
  }
  return 0;
}
