#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y, sz;
vector<int> v;
vector<vector<int> > ans;
void solve() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  ans.clear();
  sz = 0;
  vector<int> par(n + 1, 0);
  vector<bool> mark(n + 1, 0);
  while (n) {
    vector<int> last(n + 1, 1e6), Sz(n, 0);
    last[0] = -1;
    int lar = 0;
    for (int i = 0; i < n; ++i) {
      int plen = lower_bound(last.begin(), last.end(), v[i]) - last.begin();
      Sz[i] = plen, last[plen] = v[i], par[v[i]] = last[plen - 1];
      lar = max(lar, plen);
    }
    if (lar * 1LL * (lar + 1) > 2 * n) {
      vector<int> tmp;
      int cur = last[lar];
      ans.push_back(vector<int>(0));
      auto& cans = ans[sz++];
      while (cur != -1) mark[cur] = 1, cans.push_back(cur), cur = par[cur];
      reverse(cans.begin(), cans.end());
      for (int i = 0; i < n; ++i)
        if (!mark[v[i]]) tmp.push_back(v[i]);
      move(tmp.begin(), tmp.end(), v.begin());
      n -= lar;
    } else {
      for (int i = 0; i < lar; ++i) ans.push_back(vector<int>(0));
      for (int i = 0; i < n; ++i) ans[sz + Sz[i] - 1].push_back(v[i]);
      break;
    }
  }
  cout << ans.size() << '\n';
  for (auto& it : ans) {
    cout << it.size() << " ";
    for (auto& it1 : it) cout << it1 << " ";
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) solve();
  return 0;
}
