#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
const string FILENAME = "input";
const int MAXN = 100228;
int n;
vector<vector<int> > st;
void getkek(vector<int> a) {
  while (true) {
    bool bad = false, bad1 = false;
    for (int i = 0; i < (int)(a).size() - 1; i++) {
      if (a[i] < a[i + 1]) {
        bad = true;
      } else {
        bad1 = true;
      }
    }
    if (!bad || !bad1) {
      st.push_back(a);
      return;
    }
    vector<int> dp;
    dp.resize((int)(a).size() + 1);
    vector<int> who;
    who.resize((int)(a).size() + 1);
    for (int i = 1; i <= (int)(a).size(); i++) {
      dp[i] = 1e9;
    }
    vector<int> kek;
    vector<int> pr;
    pr.resize((int)(a).size());
    kek.resize((int)(a).size());
    who[0] = -1;
    int t = 0;
    int last = -1;
    vector<bool> used;
    used.resize((int)(a).size());
    for (int i = 0; i < (int)(a).size(); i++) {
      int pos = lower_bound((dp).begin(), (dp).end(), a[i]) - dp.begin();
      pos--;
      used[i] = 0;
      kek[i] = pos + 1;
      chkmax(t, kek[i]);
      if (t == kek[i]) {
        last = i;
      }
      pr[i] = who[pos];
      if (dp[pos + 1] > a[i]) {
        dp[pos + 1] = a[i];
        who[pos + 1] = i;
      }
    }
    if (t * (t + 1) > (int)(a).size() * 2) {
      vector<int> f;
      while (last != -1) {
        f.push_back(a[last]);
        used[last] = true;
        last = pr[last];
      }
      reverse((f).begin(), (f).end());
      st.push_back(f);
      vector<int> a1;
      for (int i = 0; i < (int)(a).size(); i++) {
        if (!used[i]) {
          a1.push_back(a[i]);
        }
      }
      a = a1;
      continue;
    }
    vector<vector<int> > g;
    g.resize((int)(a).size() + 1);
    for (int i = 0; i < (int)(a).size(); i++) {
      g[kek[i]].push_back(a[i]);
    }
    for (int i = 1; i <= (int)(a).size(); i++) {
      if (!g[i].empty()) {
        st.push_back(g[i]);
      }
    }
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int it = 0; it < t; it++) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    st.clear();
    getkek(a);
    cout << (int)(st).size() << '\n';
    for (auto x : st) {
      cout << (int)(x).size();
      for (auto y : x) {
        cout << ' ' << y;
      }
      cout << '\n';
    }
  }
  return 0;
}
