#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Vi = vector<int>;
void run();
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(18);
  run();
  return 0;
}
int uplg(int n) { return 32 - __builtin_clz(n); }
int uplg(ll n) { return 64 - __builtin_clzll(n); }
Vi split(const Vi& seq, vector<Vi>& lds) {
  Vi dp, ind, par;
  lds.clear();
  for (int i = (0); i < (int((seq).size())); i++) {
    int pos = int(lower_bound((dp).begin(), (dp).end(), seq[i]) - dp.begin());
    if (pos == int((dp).size())) {
      dp.push_back(seq[i]);
      ind.push_back(i);
      lds.emplace_back();
    } else {
      dp[pos] = seq[i];
      ind[pos] = i;
    }
    par.push_back(pos > 0 ? ind[pos - 1] : -1);
    lds[pos].push_back(seq[i]);
  }
  int i = ind.back();
  Vi lis;
  while (i != -1) {
    lis.push_back(seq[i]);
    i = par[i];
  }
  reverse((lis).begin(), (lis).end());
  return lis;
}
Vi filter(const Vi& seq, const Vi& sub) {
  Vi ret;
  int i = 0;
  for (auto& c : (seq)) {
    if (i >= int((sub).size()) || sub[i] != c) {
      ret.push_back(c);
    } else {
      i++;
    }
  }
  return ret;
}
void handle() {
  int n;
  cin >> n;
  Vi seq(n);
  for (auto& s : (seq)) cin >> s;
  vector<Vi> ans;
  while (!seq.empty()) {
    vector<Vi> lds;
    Vi lis = split(seq, lds);
    if (int((lis).size()) * (int((lis).size()) + 1) / 2 < int((seq).size())) {
      ans.insert(ans.end(), (lds).begin(), (lds).end());
      break;
    }
    ans.push_back(lis);
    seq = filter(seq, lis);
  }
  cout << int((ans).size()) << '\n';
  for (auto& a : (ans)) {
    cout << int((a).size()) << ' ';
    for (auto& k : (a)) cout << k << ' ';
    cout << '\n';
  }
}
void run() {
  int t;
  cin >> t;
  while (t--) handle();
}
