#include <bits/stdc++.h>
using namespace std;
void solve(int n) {
vector<bool> u(n + 1);
vector<vector<int>> g;
for (int y = n; y >= 1; y--)
if (!u[y]) {
int x = y;
while (--x && (u[x] || (x & y)));
if (x)g.push_back({x, y}), u[x] = u[y] = 1;
}
vector<int> z = {0};
for (int x = 1; x <= n; x++)
if (!u[x]) z.push_back(x);
g.push_back(z);
cout << g.size() << '\n';
for (auto&v : g) {
cout << v.size();
for (int x : v)cout << ' ' << x;
cout << '\n';
}
}
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
solve(n);
}
return 0;
}