#include <iostream>
#include <cassert>
using namespace std;

#define NAX int(2e5+1)
int n;

void solve_less(){
	int num_steps = 0;
	
	for(int i=3;i<n;i++){
		num_steps++;
	}
	
	int cur = n;
	while(cur > 1){
		cur = (cur + 1) / 2;
		num_steps++;
	}
	
	assert(num_steps <= n+5);
	
	cout << num_steps << '\n';
	
	for(int i=3;i<n;i++){
		num_steps++;
		cout << i << ' ' << n << '\n';
	}
	
	cur = n;
	while(cur > 1){
		cur = (cur + 1) / 2;
		num_steps++;
		cout << n << ' ' << 2 << '\n';
	}
}

void solve(){
	cin >> n;
	if(n <= 12){
		solve_less();
		return;
	}
	
	int num_steps = 0;
	
	for(int i=3;i<n;i++){
		if(i != 12 and i != 4){
			num_steps++;
			// cout << i << ' ' << n << '\n';
		}
	}
	
	int cur = n;
	while(cur > 1){
		num_steps++;
		cur = (cur + 11) / 12;
		// cout << n << ' ' << 12 << '\n';
	}
	
	cur = 12;
	while(cur > 1){
		num_steps++;
		cur = (cur + 3) / 4;
		// cout << 12 << ' ' << 4 << '\n';
	}
	
	cur = 4;
	while(cur > 1){
		num_steps++;
		cur = (cur + 1) / 2;
		// cout << 4 << ' ' << 2 << '\n';
	}
	
	cout << num_steps << '\n';
	
	for(int i=3;i<n;i++){
		if(i != 12 and i != 4){
			num_steps++;
			cout << i << ' ' << n << '\n';
		}
	}
	
	cur = n;
	while(cur > 1){
		num_steps++;
		cur = (cur + 11) / 12;
		cout << n << ' ' << 12 << '\n';
	}
	
	cur = 12;
	while(cur > 1){
		num_steps++;
		cur = (cur + 3) / 4;
		cout << 12 << ' ' << 4 << '\n';
	}
	
	cur = 4;
	while(cur > 1){
		num_steps++;
		cur = (cur + 1) / 2;
		cout << 4 << ' ' << 2 << '\n';
	}
}

int main(){
	int test; cin >> test;
	while(test--){
		solve();
	}
}