#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
#define vi vector<int> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define B begin()
#define E end()
 
 
int32_t main()
{
IOS;
int t;
cin >> t;
while(t--)
{
    int n;
    cin >> n;
    vector<pair<int,int>> v;
    if(n<=8)
    {
        for(int i=3;i<n;i++)
        {
            v.pb({i,n});
        }
        int k=n;
        while(n!=1)
        {
            v.pb({k,2});
            n = (n+1)/2;
        }
    }
    else
    {
        for(int i=3;i<n;i++)
        {
            if(i==8) continue;
            v.pb({i,n});
        }
        int k=n;
        while(n!=1)
        {
            v.pb({k,8});
            n = (n+7)/8;
        }
        v.pb({8,2});
        v.pb({8,2});
        v.pb({8,2});

    }
    cout << v.size() << endl;
    for(auto i: v)
    {
        cout << i.ff << " " << i.ss << endl;
    }
}


return 0;
}