#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int N = 100228;
int p[N];
int f[N];
vector<vector<int>> fnd(const vector<int>& a) {
  vector<int> last = {0};
  vector<vector<int>> v = {{0}};
  for (int x : a) {
    int id = lower_bound(last.begin(), last.end(), x) - last.begin();
    if (id == last.size()) {
      v.emplace_back();
      last.emplace_back(0);
    }
    p[x] = last[id - 1];
    v[id].push_back(x);
    last[id] = x;
  }
  int n = a.size();
  if (last.size() <= f[n] + 1) {
    v.erase(v.begin());
    return v;
  }
  vector<int> ans;
  int x = last.back();
  while (x) {
    ans.push_back(x);
    x = p[x];
  }
  reverse(ans.begin(), ans.end());
  return {ans};
}
bool w[N];
vector<int> anss;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) {
    cin >> x;
  }
  fill(w, w + n + 1, false);
  vector<vector<int>> ans;
  while (!a.empty()) {
    auto x = fnd(a);
    vector<int> na{};
    for (auto z : x) {
      for (int y : z) {
        w[y] = true;
      }
    }
    ans.insert(ans.end(), x.begin(), x.end());
    for (int y : a) {
      if (!w[y]) {
        na.push_back(y);
      }
    }
    a = move(na);
  }
  assert(ans.size() <= f[n]);
  cout << ans.size() << "\n";
  for (const auto& val : ans) {
    cout << val.size();
    for (int x : val) {
      cout << " " << x;
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(20);
  int cur = 0;
  for (int i = 1; i <= 1000; ++i) {
    int ncur = cur + i;
    for (int j = cur; j < min(ncur, N); ++j) {
      f[j] = i - 1;
    }
    cur = ncur;
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
  }
}
