#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MAXN = 1000 * 1000;
int a[MAXN];
int tmp_a[MAXN];
int b[MAXN];
int _prev[MAXN];
bool deleted[MAXN];
vector<int> history[MAXN];
vector<vector<int>> ans;
void find(int k, int n) {
  if (n == 0) {
    return;
  }
  if (n <= 2) {
    ans.push_back({});
    for (int i = 0; i < n; i++) {
      ans.back().push_back(a[i]);
      deleted[a[i]] = 1;
    }
    return;
  }
  for (int i = 0; i <= n; i++) {
    b[i] = MAXN;
    history[i].clear();
    _prev[i] = 0;
  }
  b[0] = 0;
  int max_ind = 0;
  for (int i = 0; i < n; i++) {
    int ind = (int)distance(b, upper_bound(b, b + n, a[i]));
    b[ind] = a[i];
    _prev[a[i]] = b[ind - 1];
    history[ind].push_back(a[i]);
    max_ind = max(max_ind, ind);
    if (max_ind == k) break;
  }
  if (max_ind < k) {
    for (int i = 1; i <= max_ind; i++) {
      ans.push_back(history[i]);
    }
  } else {
    vector<int> cur_ans;
    cur_ans.reserve(k);
    int cur_el = b[max_ind];
    while (cur_el) {
      cur_ans.push_back(cur_el);
      deleted[cur_el] = 1;
      cur_el = _prev[cur_el];
    }
    assert(cur_ans.size() == k);
    reverse(cur_ans.begin(), cur_ans.end());
    ans.push_back(cur_ans);
    int ind_tmp_a = 0;
    for (int i = 0; i < n; i++) {
      if (!deleted[a[i]]) {
        tmp_a[ind_tmp_a++] = a[i];
      }
    }
    assert(ind_tmp_a == n - k);
    for (int i = 0; i < n - k; i++) {
      a[i] = tmp_a[i];
    }
    find(k - 1, n - k);
  }
}
void solve() {
  ans.clear();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%i", a + i);
  }
  memset(deleted, 0, (sizeof deleted[0]) * (n + 1));
  int k = 1;
  while (k * (k - 1) / 2 < n) k++;
  find(k - 1, n);
  printf("%i\n", (int)ans.size());
  for (const auto& arr : ans) {
    printf("%i", (int)arr.size());
    for (auto item : arr) {
      printf(" %i", item);
    }
    printf("\n");
  }
}
int main(int argc, const char* argv[]) {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
