#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0) 
#define mod 1e9 + 7
#define pb push_back
#define vi vector<int>


int32_t main(){
    fast_io;
    int t;cin>>t;
    while(t--){
     int n;cin>>n;
     vector<pair<int,int>> ans;
     int a = n;
     vi special;
     set<int> s;
     special.pb(a);
     s.insert(a);
     a=sqrt(a);
     
     while(a>=2){
      special.pb(a+1);
      s.insert(a+1);
      a = sqrt(a);
     }
     /*for(int i=0;i<special.size();i++){
      cout<<special[i]<<" ";
     }*/
     for(int i=3;i<=n;i++){
      if(s.find(i) != s.end()){
          continue;
      }
      ans.pb({i,i+1});
     }
     
     for(int i=0;i<special.size()-1;i++){
      //cout<<"satyam"<<" ";
      ans.pb({special[i],special[i+1]});
      ans.pb({special[i],special[i+1]});
     }
     ans.pb({special[special.size()-1],2});
     ans.pb({special[special.size()-1],2});
     cout<<ans.size()<<endl;
     for(int i=0;i<ans.size();i++){
         cout<<ans[i].first<<" "<<ans[i].second<<endl;
     }
    }
    return 0;
}