#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//_CRT_SECURE_NO_WARNINGS
using namespace std;
#define IOS ios::sync_with_stdio(0);
#define int long long 
#define pb push_back
#define f first
#define si second
#define mp make_pair
signed main(){
  int q=1;
   cin>>q;
   while(q--)
   {
       int n;
    cin>>n;
    vector<pair<int,int>>p;
    for(int i=3;i<n;i++)
    {
        if(i!=4&&i!=8)
        {
            p.pb(mp(i,n));
        }
    }
    if(n>=8)
    {
        if(n!=8)
        {
        int temp=n;
        while(temp>1)
        {
            p.pb(mp(n,8));
            temp=temp/8;
            if(temp%8!=0)
            temp++;
        }
        }
    
    p.pb(mp(8,4));
    p.pb(mp(8,4));
    p.pb(mp(4,2));
    p.pb(mp(4,2));
    }
    else if(n>=4)
    {
        if(n!=4)
        {
        p.pb(mp(n,4));
        p.pb(mp(n,4));
        }
    p.pb(mp(4,2));
    p.pb(mp(4,2));
    }
    else
    {
        p.pb(mp(3,2));
        p.pb(mp(3,2));
    }
    cout<<p.size()<<endl;
    for(int i=0;i<p.size();i++)
    {
        cout<<p[i].f<<" "<<p[i].si<<endl;
    }
    
   }
}
      
       
       
       
 
    

     
       

   
             
             
     
     


         
         


     
            