#include <bits/stdc++.h>
using namespace std;
const int limit = 100005;
int n;
int p[limit];
int nactual;
int actual[limit];
int position[limit];
int removed[limit];
int ninc;
int previousinc[limit];
int seqinc[limit];
int ndec;
int previousdec[limit];
int seqdec[limit];
int godec[limit];
void computeinc() {
  ninc = 0;
  for (int i = 0; i < nactual; i++) {
    int x = actual[i];
    int inf = -1;
    int sup = ninc;
    while (inf + 1 < sup) {
      int med = (inf + sup) / 2;
      if (seqinc[med] < x)
        inf = med;
      else
        sup = med;
    }
    if (sup > 0)
      previousinc[x] = seqinc[sup - 1];
    else
      previousinc[x] = 0;
    if (sup < ninc)
      godec[x] = seqinc[sup];
    else
      godec[x] = 0;
    seqinc[sup] = x;
    if (ninc <= sup) ninc = sup + 1;
  }
}
void write(vector<vector<int> > &sol) {
  cout << int(sol.size()) << endl;
  for (int i = 0; i < int(sol.size()); i++) {
    vector<int> &so = sol[i];
    cout << int(so.size());
    for (int j = 0; j < int(so.size()); j++) cout << " " << so[j];
    cout << endl;
  }
}
void compute() {
  for (int i = 1; i <= n; i++) removed[i] = godec[i] = previousinc[i] = 0;
  vector<vector<int> > sol;
  for (;;) {
    nactual = 0;
    for (int i = 1; i <= n; i++)
      if (not removed[i]) actual[nactual++] = p[i];
    if (nactual == 0) {
      write(sol);
      return;
    }
    computeinc();
    if (ninc * (ninc + 1) / 2 < nactual) {
      for (int i = 0; i < ninc; i++) {
        vector<int> act;
        for (int u = seqinc[i]; u; u = godec[u]) act.push_back(u);
        reverse(act.begin(), act.end());
        sol.push_back(act);
      }
      write(sol);
      return;
    }
    vector<int> so;
    for (int x = seqinc[ninc - 1]; x; x = previousinc[x]) so.push_back(x);
    reverse(so.begin(), so.end());
    for (int i = 0; i < int(so.size()); i++) {
      int x = so[i];
      removed[position[x]] = 1;
    }
    sol.push_back(so);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int cases;
  cin >> cases;
  for (int cas = 0; cas < cases; cas++) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> p[i];
      position[p[i]] = i;
    }
    compute();
  }
}
