#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll
 
#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2
 
int32_t main(){
    IOS
	int t; cin>>t;
	while (t--){
		int n; cin>>n;
		vector<pii> v;
		if (n==3) v.pb({3,2}),v.pb({3,2});
		else if (n<=512){
			for (int i=4;i<n;i++) v.pb({i,i+1});

			int N=n;
			while (N>1) v.pb({n,3}),N=(N+2)/3;
			v.pb({3,2}),v.pb({3,2});
		}
		else{
			for (int i=4;i<512;i++) v.pb({i,i+1});
			for (int i=513;i<n;i++) v.pb({i,i+1});

			int N=n;
			while (N>1) v.pb({n,512}),N=(N+511)/512;
			N=512;
			while (N>1) v.pb({512,3}),N=(N+2)/3;
			v.pb({3,2}),v.pb({3,2});
		}
		assert(sz(v)<=n+5);
		cout<<sz(v)<<endl;
		for (pii i:v) cout<<i.F<<' '<<i.S<<endl;
	}
}
