/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz

    int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;

        vi v(n + 1);
        for(int i=0; i<=n; i++) v[i] = i;

        vii ans;

        if(n <= 32){
        	for(int i=n - 1; i>2; i--) ans.pb(i, n), v[i] = 1;

        	while(v[n] > 1){
        		ans.pb(n, 2);
        		v[n] = (v[n] + 1)/2;
        	}
        }
        else{
        	for(int i=n - 1; i>4; i--) if(i != 32) ans.pb(i, n), v[i] = 1;

        	while(v[n] > 1){
        		ans.pb(n, 32);
        		v[n] = (v[n] + 31)/32;
        	}

        	while(v[32] > 1){
        		ans.pb(32, 4);
        		v[32] = (v[32] + 3) / 4;
        	}

        	ans.pb(3, 4);
        	ans.pb(4, 2);
        	ans.pb(4, 2);
        }

        // for(int i=1; i<=n; i++) cout<<v[i]<<' ';
        // 	cout<<endl;

        cout<<ans.size()<<endl;
        for(auto it: ans) cout<<it.x<<' '<<it.y<<endl;
    }
}