#include <bits/stdc++.h>
using namespace std;
int N;
int a[100010];
bool covered[100010];
int x[100010];
int dp[100010];
int pre[100010];
int val_to_pos[100010];
vector<vector<int> > ANS;
int main3(int D, int pre_cut) {
  int i;
  for ((i) = 0; (i) < (int)(N + 1); (i)++) x[i] = (1 << 29);
  x[0] = 0;
  for ((i) = 0; (i) < (int)(N); (i)++)
    if (!covered[i]) {
      int high = dp[i];
      int low = max(dp[i] - pre_cut, 1) - 1;
      while (high - low > 1) {
        int mid = (low + high) / 2;
        if (x[mid] < a[i]) {
          low = mid;
        } else {
          high = mid;
        }
      }
      dp[i] = high;
      pre[a[i]] = x[low];
      x[high] = a[i];
    }
  int maxdp = 0;
  int maxdppos = -1;
  for ((i) = 0; (i) < (int)(N); (i)++)
    if (!covered[i])
      if (dp[i] > maxdp) {
        maxdp = dp[i];
        maxdppos = i;
      }
  if (maxdp <= D) {
    int sz = ANS.size();
    vector<int> empty;
    for ((i) = 0; (i) < (int)(maxdp); (i)++) ANS.push_back(empty);
    for ((i) = 0; (i) < (int)(N); (i)++)
      if (!covered[i]) ANS[sz + dp[i] - 1].push_back(a[i]);
    return -1;
  }
  int y = a[maxdppos];
  vector<int> v;
  while (y > 0) {
    v.push_back(y);
    covered[val_to_pos[y]] = true;
    y = pre[y];
  }
  reverse(v.begin(), v.end());
  ANS.push_back(v);
  return v.size();
}
void main2(void) {
  int i, j;
  for ((i) = 0; (i) < (int)(N); (i)++) val_to_pos[a[i]] = i;
  ANS.clear();
  int D = 1;
  while ((D + 1) * (D + 2) / 2 - 1 < N) D++;
  for ((i) = 0; (i) < (int)(N); (i)++) covered[i] = false;
  for ((i) = 0; (i) < (int)(N); (i)++) dp[i] = i + 1;
  int rem = N;
  int pre_cut = N + 5;
  while (1) {
    int tmp = main3(D, pre_cut);
    if (tmp == -1) break;
    D--;
    rem -= tmp;
    if (rem == 0) break;
    pre_cut = tmp;
  }
  int sz = ANS.size();
  printf("%d\n", sz);
  for ((i) = 0; (i) < (int)(sz); (i)++) {
    int len = ANS[i].size();
    printf("%d", len);
    for ((j) = 0; (j) < (int)(len); (j)++) printf(" %d", ANS[i][j]);
    printf("\n");
  }
}
int main(void) {
  int Q, q, i;
  cin >> Q;
  for ((q) = 0; (q) < (int)(Q); (q)++) {
    scanf("%d", &N);
    for ((i) = 0; (i) < (int)(N); (i)++) scanf("%d", &a[i]);
    main2();
  }
  return 0;
}
