#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int g[maxn];
int prv[maxn], id[maxn];
int a[maxn];
int b[maxn];
bool vis[maxn];
int ans;
vector<int> p[maxn];
int n;
void solve(int n);
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      vis[i] = 0;
    }
    ans = 0;
    solve(n);
    printf("%d\n", ans);
    for (int i = 1; i <= ans; i++) {
      printf("%d ", p[i].size());
      for (int j = 0; j < p[i].size(); j++) {
        printf("%d ", p[i][j]);
      }
      p[i].clear();
      printf("\n");
    }
  }
  return 0;
}
void solve(int n) {
  if (n == 1) {
    ans++;
    p[ans].push_back(a[1]);
    return;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int pos = lower_bound(g + 1, g + 1 + cnt, a[i]) - g;
    g[pos] = a[i];
    id[pos] = i;
    prv[i] = id[pos - 1];
    if (pos > cnt) cnt = pos;
  }
  if (cnt * (cnt + 1) / 2 > n) {
    ans++;
    p[ans].resize(cnt);
    int cur = id[cnt];
    for (int i = cnt - 1; i >= 0; i--) {
      p[ans][i] = a[cur];
      vis[a[cur]] = 1;
      cur = prv[cur];
    }
    int tmp = n;
    int n = 0;
    for (int i = 1; i <= tmp; i++) {
      if (!vis[a[i]]) a[++n] = a[i];
    }
    solve(n);
  } else {
    for (int i = 1; i <= cnt; i++) {
      b[i] = ::n + 1;
    }
    for (int i = 1; i <= n; i++) {
      int pos = lower_bound(b + 1, b + 1 + cnt, a[i]) - b;
      p[ans + pos].push_back(a[i]);
      b[pos] = a[i];
    }
    ans += cnt;
  }
}
