#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
  return pp1 == pp2 &&
                 (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
             ? EOF
             : *pp1++;
}
inline int read() {
  int x = 0;
  for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)
    if (nc == 45) ny = -1;
  if (nc < 0) return nc;
  for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;
       x = (x << 3) + (x << 1) + (nc ^ 48))
    ;
  return x * ny;
}
int a[MAXN], n, k, cnt, S[MAXN], b[MAXN], c[MAXN], top, lt[MAXN], nt[MAXN];
vector<int> ans[MAXN];
inline int Get() {
  for (int i = (1); i <= (top); i++) b[i] = lt[i] = nt[i] = 0;
  S[top = 1] = 1e5 + 1;
  for (int i = (1); i <= (n); i++) {
    int pos = lower_bound(S + 1, S + top + 1, a[i]) - S;
    S[pos] = a[i], lt[i] = b[pos], b[pos] = i, nt[i] = b[pos - 1];
    if (pos == top) S[++top] = 1e5 + 1;
  }
  return top - 1;
}
inline void Find(int x) {
  ans[++cnt].clear();
  for (int i = b[x]; i; i = nt[i]) ans[cnt].push_back(a[i]), a[i] = -1;
  reverse(ans[cnt].begin(), ans[cnt].end());
}
inline void Divide(int k) {
  for (int i = (1); i <= (k); i++) {
    ans[++cnt].clear();
    for (int j = b[i]; j; j = lt[j]) ans[cnt].push_back(a[j]);
    reverse(ans[cnt].begin(), ans[cnt].end());
  }
}
int main() {
  for (int t = read(); t--;) {
    n = read();
    for (int i = (1); i <= (n); i++) a[i] = read();
    cnt = 0;
    for (; n;) {
      int k = Get();
      if (1ll * k * (k + 1) > 2 * n)
        Find(k);
      else {
        Divide(k);
        break;
      }
      int tot = 0;
      for (int i = (1); i <= (n); i++)
        if (~a[i]) a[++tot] = a[i];
      n = tot;
    }
    cout << cnt << "\n";
    for (int i = (1); i <= (cnt); i++) {
      cout << ans[i].size() << " ";
      for (auto o : ans[i]) cout << o << " ";
      cout << "\n";
    }
  }
  return 0;
}
