#include <bits/stdc++.h>
using namespace std;
int T, n, pre[100005];
vector<int> st;
vector<int> LIS(vector<int> a) {
  st.clear();
  vector<int> f(((int)(a).size()));
  for (int i = 0; i < ((int)(a).size()); ++i) {
    if (st.empty() || a[i] > st.back())
      st.emplace_back(a[i]), f[i] = ((int)(st).size()), pre[a[i]] = 0;
    else {
      auto it = lower_bound(st.begin(), st.end(), a[i]);
      pre[a[i]] = *it, *it = a[i];
      f[i] = it - st.begin() + 1;
    }
  }
  int i = max_element(f.begin(), f.end()) - f.begin(), cur = f[i], num = 1e9;
  vector<int> b;
  for (; i >= 0; --i) {
    if (f[i] == cur && a[i] < num) {
      num = a[i];
      --cur;
      b.emplace_back(a[i]);
    }
  }
  assert(cur == 0);
  reverse(b.begin(), b.end());
  return b;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    vector<vector<int> > ans;
    while (((int)(a).size())) {
      vector<int> b(LIS(a));
      if (((int)(b).size()) * (((int)(b).size()) + 1) > 2 * ((int)(a).size())) {
        ans.push_back(b);
        vector<int> aa;
        for (int i = 0, j = 0; i < ((int)(a).size()); ++i) {
          if (j >= ((int)(b).size()) || a[i] != b[j]) aa.emplace_back(a[i]);
          if (j < ((int)(b).size()) && a[i] == b[j]) ++j;
        }
        a = aa;
      } else {
        for (auto x : st) {
          ans.push_back({});
          for (int y = x; y; y = pre[y]) {
            ans.back().push_back(y);
          }
          reverse(ans.back().begin(), ans.back().end());
        }
        break;
      }
    }
    printf("%d\n", ((int)(ans).size()));
    for (auto& cur : ans) {
      printf("%d ", ((int)(cur).size()));
      for (int i = (0); i <= (((int)(cur).size()) - 1); ++i)
        printf("%d%c", cur[i], i == ((int)(cur).size()) - 1 ? '\n' : ' ');
    }
  }
  return 0;
}
