#include<iostream>
#include<bits/stdc++.h>
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long 
#define li long int 
#define pp pair<int,int> 
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i,x,n) for(int i=x;i<n;i++)
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
ll binpow(ll a, ll b) {
    a %= mod;  long long res = 1;
    while (b > 0) { if (b & 1)res = res * a % mod;
        a = a * a % mod; b >>= 1;}
       return res;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int z=n;
        vector<pp>v;
        for(int i=n-1;i>=2;i--)
        {
            int x;
            if(z%i==0)
            x=z/i;
            else
            x=(z/i)+1;
            
            while(x>=i){
             v.pb(mk(n,i));
               z=x;
            if(z%i==0)
            x=z/i;
            else
            x=(z/i)+1;
            }
            v.pb(mk(i,n));
        }
        cout<<v.size()<<endl;
        llp(i,0,v.size())cout<<v[i].fr<<" "<<v[i].ss<<endl;
        
    }
      
}
