#include<iostream>
#include<vector>
using namespace std;
int ceil(int x,int y){
    return (x+y-1)/y;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        
        int count=0;
        //start from n cancel all numbers until it reaches n/2
        //root(n) wil cancel n
        vector<int> v;
        int x=2,y=3;
        v.push_back(x);
        while(y<=n){
            if(ceil(y,x)==x){
                v.push_back(y);
                count+=(y-x+1);
                x=y;
            }
            y++;
        }
        count+=(n-x+1);
        if(n==x){
            count--;
        }
        cout<<count<<endl;
        int l;
        while(!v.empty()){
            l=v.back();v.pop_back();
            if(n==l){
                l=v.back();v.pop_back();
            }
            //x-y++1 steps
            for(int i=n-1;i>=(l+1);i--){
                cout<<i<<" "<<n<<endl;
            }
            // if(n==l){
            //     cout<<n<<" "<<l<<endl;
            // }
            // else{
            cout<<n<<" "<<l<<endl;
            cout<<n<<" "<<l<<endl;
            // }

            n=l;
        }
    }
    
}
