#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline int chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline int chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
int n;
int p[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
}
bool used[MAXN];
int b[MAXN], f[MAXN];
vector<int> save[MAXN];
vector<int> get_lis() {
  int answer = 0;
  vector<int> ret;
  for (int i = 0; i <= n; i++) save[i].clear();
  for (int i = 0; i < n; i++)
    if (!used[i]) {
      f[i] = lower_bound(b + 1, b + answer + 1, p[i]) - b;
      chkmax(answer, f[i]);
      b[f[i]] = p[i];
      save[f[i]].push_back(i);
    }
  int req = answer;
  for (int i = n - 1; i >= 0; i--)
    if (!used[i] && f[i] == req) {
      ret.push_back(i);
      req--;
    }
  reverse(ret.begin(), ret.end());
  return ret;
}
void solve() {
  vector<vector<int> > answer;
  for (int i = 0; i < n; i++) used[i] = 0;
  int N = n;
  while (true) {
    vector<int> lis = get_lis();
    int L = ((int)lis.size());
    if (L == 0) break;
    int k = 1;
    while (k * (k + 1) / 2 <= N) k++;
    k--;
    if (L > k) {
      answer.push_back(lis);
      for (int i : lis) N--, used[i] = true;
    } else {
      for (int i = 1; i <= L; i++) answer.push_back(save[i]);
      break;
    }
  }
  cout << ((int)answer.size()) << '\n';
  for (auto &it : answer) {
    cout << ((int)it.size()) << " ";
    for (int x : it) cout << p[x] << " ";
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    read();
    solve();
  }
  return 0;
}
