    /*author:	Slns*/

#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair < int, int > pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;

void NITRO(){
	//OneInOneOut
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

const int N = 1e+5 * 3 + 11;
const ll MOD = 1e+9 + 7; // 888244353;
const int inf = int(1e9);
const ll INF = ll(1e16);

void SOLVE(/*WATLE*/) {
	int n;
	cin >> n;
	vector <pll> v;
	while(n > 2) {
		int t = sqrt(n);
		if(t * t != n)t++;
		for(int i = t + 1; i < n; i++) v.pb({i, n});
		v.pb({n, t}), v.pb({n, t});
		n = t;
	}
	cout << v.size() << '\n';
	for(int i = 0; i < int(v.size()); i++){
		cout << v[i].ff << " " << v[i].ss << '\n';
	}
}

int main() {
    //  freopen("slalom.in", "r", stdin);
    //  freopen("slalom.out", "w", stdout);
    NITRO();
    int times = 1;
	cin >> times;
    for(int i = 1; i <= times; i++) {
        //cout << "Case #" << t << ": ";
        SOLVE();
    }
    return 0;
}
