#include <bits/stdc++.h>
using namespace std;
int fro[200005], vis[200005], top, a[200005], n, m, xinyue, sta[200005], tot,
    inf = 1e9, k, now;
vector<int> vec[200005];
set<pair<int, int> > st;
void get_l() {
  top = 0;
  for (int i = 1; i <= n; i++) fro[i] = vis[i] = 0;
  for (int i = 1; i <= n; i++) {
    int l = 0, r = top, ans = 0;
    while (l <= r) {
      int mid = l + r >> 1;
      if (a[sta[mid]] < a[i]) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    fro[i] = sta[ans];
    sta[ans + 1] = i;
    if (ans == top) top++;
  }
}
void del(int x) {
  if (!x) return;
  del(fro[x]);
  vis[x] = 1;
  vec[tot].push_back(a[x]);
}
void work() {
  st.clear();
  for (int i = 1; i <= top; i++) {
    st.insert(make_pair(inf, tot + i));
  }
  tot += top;
  for (int i = 1; i <= n; i++) {
    pair<int, int> qwq = *st.lower_bound(make_pair(a[i], 0));
    st.erase(qwq);
    vec[qwq.second].push_back(a[i]);
    st.insert(make_pair(a[i], qwq.second));
  }
}
int main() {
  scanf("%d", &xinyue);
  while (xinyue--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    k = 0;
    tot = 0;
    while (k * (k + 1) / 2 < n) k++;
    while (n) {
      get_l();
      if (top < k) {
        work();
        break;
      } else {
        tot++;
        del(sta[top]);
        now = 0;
        for (int i = 1; i <= n; i++) {
          if (!vis[i]) a[++now] = a[i];
        }
        n = now;
        k--;
      }
    }
    printf("%d\n", tot);
    for (int i = 1; i <= tot; i++) {
      printf("%d ", vec[i].size());
      for (int t = 0; t < vec[i].size(); t++) {
        printf("%d ", vec[i][t]);
      }
      printf("\n");
      vec[i].clear();
    }
  }
}
