#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = (1 << 29);
int n;
int a[maxn];
bool covered[maxn];
int x[maxn], dp[maxn], pre[maxn];
int val_to_pos[maxn];
vector<vector<int> > res;
int ssolve(int d, int pre_cut) {
  for (int i = 0; i <= n; i++) {
    x[i] = inf;
  }
  x[0] = 0;
  for (int i = 0; i < n; i++) {
    if (!covered[i]) {
      int low = max(dp[i] - pre_cut, 1) - 1, high = dp[i];
      while (high - low > 1) {
        int mid = (low + high) / 2;
        if (x[mid] < a[i]) {
          low = mid;
        } else {
          high = mid;
        }
      }
      dp[i] = high;
      pre[a[i]] = x[low];
      x[high] = a[i];
    }
  }
  int maxdp = 0, maxdppos = -1;
  for (int i = 0; i < n; i++) {
    if (!covered[i]) {
      if (dp[i] > maxdp) {
        maxdp = dp[i];
        maxdppos = i;
      }
    }
  }
  if (maxdp <= d) {
    int sz = res.size();
    vector<int> empty;
    for (int i = 0; i < maxdp; i++) {
      res.push_back(empty);
    }
    for (int i = 0; i < n; i++) {
      if (!covered[i]) {
        res[sz + dp[i] - 1].push_back(a[i]);
      }
    }
    return -1;
  }
  int y = a[maxdppos];
  vector<int> v;
  while (y > 0) {
    v.push_back(y);
    covered[val_to_pos[y]] = true;
    y = pre[y];
  }
  reverse(v.begin(), v.end());
  res.push_back(v);
  return v.size();
}
void solve() {
  for (int i = 0; i < n; i++) {
    covered[i] = false;
    dp[i] = i + 1;
    val_to_pos[a[i]] = i;
  }
  res.clear();
  int d = 1;
  while ((d + 1) * (d + 2) / 2 - 1 < n) {
    d++;
  }
  int rem = n;
  int pre_cut = n + 5;
  while (1) {
    int tmp = ssolve(d, pre_cut);
    if (tmp == -1) {
      break;
    }
    d--;
    rem -= tmp;
    if (rem == 0) {
      break;
    }
    pre_cut = tmp;
  }
  int sz = res.size();
  cout << sz << '\n';
  for (int i = 0; i < sz; i++) {
    int len = res[i].size();
    cout << len;
    for (int j = 0; j < len; j++) cout << ' ' << res[i][j];
    cout << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    solve();
  }
  return 0;
}
