#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int q[N], a[N], vis[N];
vector<int> ans[N];
int n, res, k, f[N], fr[N];
void solve(int k) {
  int mx = 0;
  q[0] = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (!vis[a[i]]) {
      int l = 1, r = mx, ans = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (a[q[mid]] < a[i])
          ans = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      f[i] = ans;
      fr[i] = q[ans];
      q[ans + 1] = i;
      mx = max(mx, ans + 1);
    }
  if (mx >= k) {
    ++res;
    for (int i = q[mx]; i; i = fr[i]) ans[res].push_back(a[i]), vis[a[i]] = 1;
    reverse(ans[res].begin(), ans[res].end());
    solve(k - 1);
  } else {
    for (int i = (int)(1); i <= (int)(n); i++)
      if (!vis[a[i]]) ans[res + f[i] + 1].push_back(a[i]);
    res += mx;
  }
}
void solve() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) vis[i] = 0;
  res = 0;
  for (k = 1; k * (k + 1) / 2 <= n; ++k)
    ;
  solve(k);
  printf("%d\n", res);
  for (int i = (int)(1); i <= (int)(res); i++) {
    printf("%d", ans[i].size());
    for (auto j : ans[i]) printf(" %d", j);
    ans[i].resize(0);
    puts("");
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
}
