#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int big[N];
int n, a[N], len[N], pre[N];
int lis() {
  vector<int> dp, id;
  for (int i = 0; i < (int)(n); i++) {
    int pos = lower_bound((dp).begin(), (dp).end(), a[i]) - dp.begin();
    if (pos == ((int)(dp).size())) dp.push_back(0), id.push_back(0);
    dp[pos] = a[i];
    id[pos] = i;
    len[i] = pos + 1;
    pre[i] = (pos > 0 ? id[pos - 1] : -1);
  }
  return id.back();
}
vector<vector<int> > ans;
void printAll() {
  cout << ((int)(ans).size()) << '\n';
  for (auto &v : ans) {
    cout << ((int)(v).size());
    for (auto x : v) cout << ' ' << x;
    cout << '\n';
  }
}
void print(const vector<int> &v) { ans.push_back(v); }
void eraseLIS(int last) {
  vector<int> seq, used(n);
  for (int i = last; i >= 0; i = pre[i]) {
    seq.push_back(a[i]);
    used[i] = 1;
  }
  reverse((seq).begin(), (seq).end());
  print(seq);
  int nn = 0;
  for (int i = 0; i < (int)(n); i++)
    if (!used[i]) a[nn++] = a[i];
  n = nn;
}
void solve() {
  ans.clear();
  while (n > 0) {
    int goal = big[n], last = lis(), can = len[last];
    if (can > goal) {
      eraseLIS(last);
    } else {
      vector<vector<int> > ans(can);
      for (int i = 0; i < (int)(n); i++) ans[len[i] - 1].push_back(a[i]);
      for (auto &v : ans) print(v);
      n = 0;
    }
  }
  printAll();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int st = 1;
  for (int x = 1;; x++) {
    for (int k = st; k <= st + x; k++) {
      if (k >= N) goto outer;
      big[k] = x;
    }
    st += x + 1;
  }
outer:;
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 0; i < (int)(n); i++) cin >> a[i];
    solve();
  }
  return 0;
}
