#include <bits/stdc++.h>
using namespace std;
#define cp ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int  
#define vint vector<int>
#define vllint vector<ll>
#define pair_int pair<int , int>
#define pair_ll_int pair<ll , ll>
#define vector_of_pair_int vector<pair_int>
#define pb push_back 
#define test_case int t; cin>>t; while(t--)
#define umap unordered_map <int,int> 
#define mapint map<int,int>
#define infinity 1000000000
#define mp make_pair

int main() 
{ 
	cp
    
    test_case
    {
       ll n;
       cin>>n;

       if(n<=256)
       {
         int count=0;       	
         ll temp=n;
       	 while(temp!=1)
       	 {
       	 	count++;
       	 	if(temp%2==0)
       	 		temp=temp/2;
       	 	else
       	 		temp=temp/2+1;
       	 }

       	 cout<<count+n-3<<endl;
        
         for (int i = 1; i <=n-3; ++i)
       	 {
       	 	/* code */
       	 	 cout<<3+i-1<<" "<<3+i<<endl;
       	 }

       	 for (int i = 0; i < count; ++i)
       	 {
       	 	/* code */
       	 	cout<<n<<" "<<2<<endl;
       	 }

       	 




       }
       else
       {
       	 int count=0;       	
         ll temp=n;
       	 while(temp!=1)
       	 {
       	 	count++;
       	 	
       	 	temp=ceil(float(temp)/float(16));
       	 }

       	 cout<<count+n<<endl;
         
         for (int i = 3; i <n; ++i)
       	 {
       	 	/* code */
             if(i!=16)
             {
             	cout<<i<<" "<<i+1<<endl;
             }

       	 }
          
           for (int i = 0; i < count; ++i)
       	 {
       	 	/* code */
       	 	cout<<n<<" "<<16<<endl;
       	 }
       	 
       	 for (int i = 0; i < 4; ++i)
       	 {
       	 	/* code */
       	 	cout<<16<<" "<<2<<endl;
       	 }
       	 
       	
       }
    }

    return 0; 
} 