#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
const int N = 200010;
int n;
int a[N];
vector<int>v;
void solve() {
cin >> n;
v.clear();
int cnt = 0;
if (n <= 32) {
for (int i = 3; i < n; ++i) {
v.push_back(i);
v.push_back(i + 1);
cnt++;
}
int t = n;
while (t != 1) {
//printf("%d %d\n", n, 2);
v.push_back(n);
v.push_back(2);
cnt++;
t = ceil(double(t / 2.0));
//cout << "t == " << t << endl;
}
}
else {
int x = ceil(pow(n, 1.0 / 5.0));
for (int i = 3; i < n; ++i) {
if (i != x) {
//printf("%d %d\n", i, i + 1);
v.push_back(i);
v.push_back(i + 1);
cnt++;
}
}
int t = n;
while (t != 1) {
//printf("%d %d\n", n, x);
v.push_back(n);
v.push_back(x);
cnt++;
t = ceil(double((t * 1.0) / (x * 1.0)));
}
t = x;
while (t != 1) {
//printf("%d %d\n", x, 2);
v.push_back(x);
v.push_back(2);
cnt++;
t = ceil(double(t / 2.0));
}
}
cout << cnt << endl;
for (int i = 0; i < v.size(); ++i) {
printf("%d ", v[i]);
if (i & 1)cout << endl;
}
}
int main() {
int t; cin >> t;
while(t--)
solve();
return 0;
}