#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
const int mod=1e9+7;
int main()
{
 
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n<=32)
        {
            ll m=n-3;
            m+=5;
            cout<<m<<endl;
            for(ll i=3; i<n; i++)
            {
                cout<<i<<" "<<n<<endl;
            }
            for(ll i=0; i<5; i++)
            {
                cout<<n<<" "<<2<<endl;
            }
        }
        else
        {
            ll m = n-4;
            m+=9;
            cout<<m<<endl;
            for(ll i=3; i<n; i++)
            {
                if(i==16)
                    continue;
                cout<<i<<" "<<n<<endl;
            }
 
            for(ll i=0; i<5; i++)
            {
                cout<<n<<" "<<16<<endl;
            }
 
            for(ll i=0; i<4; i++)
            {
                cout<<16<<" "<<2<<endl;
            }
            //cout<<m<<nn;
        }
    }
}