#include<bits/stdc++.h>
using namespace std;

int main()
{
   int t,n; cin >> t;
   
   while(t--)
   {
       cin >> n; int ans=0,k=n,p=n,h=0;
       
       
       while(ceil(sqrt(k))>=2 && k>2)
       {
           ans++; k=ceil(sqrt(k));
       }
       
       cout << ans+n-2 << endl; k=n; int i=k-1;
       while(k>2)
       {   
           int p=ceil(sqrt(k));
           while(i>p)
           {
              cout << i <<" " << k << endl; i--; 
           }
           
     cout<< k << " " << i << endl; cout << k << " " << i << endl; 
           k=ceil(sqrt(k)); i=k-1;
       }
   }
    return 0;
}