#include <bits/stdc++.h>
const int N = 100010, INF = 0x3f3f3f3f;
int p[N], cnt;
std::vector<int> v[N];
struct Node {
  int nex, pre;
} node[N];
int tp, head = N - 1, tail = N - 2;
int stk[N], top, f[N], rest, stk2[N], fr[N];
bool vis[N];
inline void del(int x) {
  int nex = node[x].nex, pre = node[x].pre;
  node[nex].pre = pre;
  node[pre].nex = nex;
  return;
}
inline int getLIS() {
  top = 0;
  for (int i = node[head].nex; i != tail; i = node[i].nex) {
    int l = 0, r = top;
    while (l < r) {
      int mid = (l + r + 1) >> 1;
      if (stk[mid] < p[i]) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }
    f[i] = r + 1;
    fr[i] = stk2[r];
    stk[r + 1] = p[i];
    stk2[r + 1] = i;
    if (r == top) ++top;
  }
  return top;
}
inline void erase() {
  int x = stk2[top];
  ++cnt;
  while (x) {
    del(x);
    v[cnt].push_back(p[x]);
    x = fr[x];
  }
  std::reverse(v[cnt].begin(), v[cnt].end());
  return;
}
inline void split() {
  while (rest) {
    ++cnt;
    int last = -1;
    for (int i = node[tail].pre; i != head; i = node[i].pre) {
      if (p[i] > last) {
        v[cnt].push_back(i);
        last = p[i];
        rest--;
      }
    }
    std::reverse(v[cnt].begin(), v[cnt].end());
    int len = v[cnt].size();
    for (int i = 0; i < len; i++) {
      del(v[cnt][i]);
      v[cnt][i] = p[v[cnt][i]];
    }
  }
  return;
}
inline void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    node[i].nex = 0;
    if (i > 1) {
      node[i].pre = i - 1;
      node[i - 1].nex = i;
    } else {
      node[i].pre = head;
      node[head].nex = i;
    }
  }
  node[n].nex = tail;
  node[tail].pre = n;
  cnt = 0;
  rest = n;
  int K = 1;
  while (K * (K + 1) / 2 <= n) {
    ++K;
  }
  while (rest) {
    int len = getLIS();
    if (len >= K) {
      erase();
      K--;
      rest -= len;
    } else {
      split();
      rest = 0;
    }
  }
  printf("%d \n", cnt);
  for (int i = 1; i <= cnt; i++) {
    int len = v[i].size();
    printf("%d ", len);
    for (int j = 0; j < len; j++) {
      printf("%d ", v[i][j]);
    }
    puts("");
    v[i].clear();
  }
  tp = 0;
  return;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
