#include <iostream>
#include<bits/stdc++.h>
#define li long long int
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--){

        li n;
        cin>>n;

        vector<pair<li,li> > ans;

        // appproach --> optimal soln --> we keep 1 and 2 as they are
        // change the rest n-2 numbers with 1
        // numbers from 3 to n-1 can be easily changed to 1 in (n-4) operations
        // now the question would to reduce n to 1
        // therefore try and reduce n at every step when converting numbers from (n-1 to 3) to 1

        li temp=n;

        for(int i=(n-1);i>=3;i--){

            // check if reducing n to n/i is optimal

            // ceil value --> (n+i-1)/i

            if( ((temp+i-1)/i)>=i ){

                ans.push_back(make_pair(n,i));
                temp=(temp+i-1)/i;

            }

            // compulsory step --> of converting i to 1

            ans.push_back(make_pair(i,n));

        }

        if(temp>1){

            while(temp>1){
                ans.push_back(make_pair(n,2));
                temp=(temp+1)/2;

            }


        }

        if(ans.size()<=(n+5)){

            int nn=ans.size();

            cout<<nn<<endl;

            for(int i=0;i<nn;i++){

                cout<<ans[i].first<<" "<<ans[i].second<<endl;;

            }

        }


    }

    return 0;
}
