#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
int main()
{
  FIO
  int tt;cin>>tt;
  while(tt--){
      int n;cin>>n;
      ll u=2;
      set<int>ss;
      int v=0;
      while(u<=n){
       
          ss.insert(u);
          v++;
          u*=u;

      }
      
      if(u>n)u=sqrt(u);
      
      int m = n-2-v+2*(v-1)+(( u == n )?1:2);
      cout<<m<<"\n";
      for(int i=2;i<n;i++){
          if(ss.find(i)==ss.end()){
            
              cout<<i<<" "<<n<<"\n";
          }
      }
      
      


      if(u!=n){
       
          
          cout<<n<<" "<<u<<"\n";
          cout<<n<<" "<<u<<"\n";
          
      }
      

      while(u>2){
        
          cout<<u<<" "<<sqrt(u)<<"\n";
          cout<<u<<" "<<sqrt(u)<<"\n";
          u=sqrt(u);
      }

    
      

  }
 
 
 
return 0;
   
}