#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n" 
#define MOD 1000000007

const int MAXN = 2e5 +15;
using namespace std;



void solve(){	
	int n,m; cin>>n;
	m = n;
	vector<pair<int,int> > v;
	while(m>3){
		n=m;
		for(ll i=n-1; i*i>=n; i--){
			m = i;
			if((i-1)*(i-1) < n) break;
			v.pb({i,n});
		}
		v.pb({n,m}); v.pb({n,m});
	}
	if(m == 3){
		v.pb({3,2});
		v.pb({3,2});
	} 
	cout<<v.size();
	for(auto pp: v){
		cout<<"\n"<<pp.f<<" "<<pp.s;
	}


}
 
int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);	
	cout<<fixed<<setprecision(12);

	int t =1; cin>>t;
	for(int i=1; i<= t; i++){
		solve();
		cout<<"\n";
	}
	
	return 0;
}