#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
int wut[MAXN];
int dp[MAXN];
int doit(const vector<int>& ar) {
  int n = (int)(ar).size();
  memset(wut, 127, (n + 1) * 4);
  memset(dp, 0, n * 4);
  wut[0] = -1;
  int res = 0;
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    auto it = lower_bound(wut, wut + n + 1, ar[i]);
    dp[i] = it - wut;
    res = max(res, dp[i]);
    if (wut[dp[i] - 1] < ar[i] && ar[i] < wut[dp[i]]) wut[dp[i]] = ar[i];
  }
  return res;
}
bool marked[MAXN];
vector<vector<int>> ans;
void cut(vector<int>& ar, int res) {
  ans.emplace_back();
  memset(marked, 0, (int)(ar).size());
  int cur;
  for (cur = 0; dp[cur] < res; ++cur)
    ;
  marked[cur] = true;
  ans.back().push_back(ar[cur]);
  while (dp[cur] > 1) {
    int prv = cur;
    while (ar[prv] > ar[cur] || dp[prv] != dp[cur] - 1) --prv;
    marked[prv] = true;
    cur = prv;
    ans.back().push_back(ar[cur]);
  }
  reverse((ans.back()).begin(), (ans.back()).end());
  int j = 0;
  for (int(i) = 0; (i) < (int)((int)(ar).size()); (i)++) {
    if (marked[i]) continue;
    ar[j] = ar[i];
    ++j;
  }
  ar.resize(j);
}
int expected[MAXN];
void solve() {
  ans.clear();
  int n;
  cin >> n;
  vector<int> ar(n);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    cin >> ar[i];
    --ar[i];
  }
  while (!ar.empty()) {
    int done = doit(ar);
    if (done > expected[(int)(ar).size()]) {
      cut(ar, done);
      continue;
    }
    int old_size = (int)(ans).size();
    ans.resize(old_size + done);
    for (int(i) = 0; (i) < (int)((int)(ar).size()); (i)++)
      ans[old_size + dp[i] - 1].push_back(ar[i]);
    break;
  }
  if ((int)(ans).size() > expected[n]) throw;
  cout << (int)(ans).size() << '\n';
  for (auto e : ans) {
    cout << (int)(e).size();
    for (auto f : e) cout << ' ' << f + 1;
    cout << '\n';
  }
}
int main() {
  for (int i = 1; i * (i + 1) / 2 < MAXN; ++i) expected[i * (i + 1) / 2] = i;
  for (int i = 1; i < MAXN; ++i)
    expected[i] = max(expected[i], expected[i - 1]);
  int t;
  cin >> t;
  for (int(test) = 0; (test) < (int)(t); (test)++) solve();
}
