#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf INT_MAX
#define minf INT_MIN
using namespace std;


void solve(){
    ll n;
    cin>>n;
    ll x=65536;
    while(x>=n){
        x=sqrt(x);
    }
    vector<pair<ll,ll> >ans;
    for(ll i=3;i<n;i++){
        if(i==4 || i==16 || i==256 || i==65536)
        continue;
        ans.push_back(make_pair(i,i+1));
        
    }
    ll k=n;
    while(k!=2){
        ans.push_back(make_pair(k,x));
        ans.push_back(make_pair(k,x));
        k=x;
        x=sqrt(x);
    }
    cout<<ans.size()<<endl;
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i].first<<" "<<ans[i].second<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--) solve();
} 