#include <bits/stdc++.h>
//memset(,0, sizeof );
using namespace std;
#define fastIO ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef long int li;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pi;
const int N = 1e9;
const int mod = 1e9 + 7;
string S = " ", E = "\n";

int main() {
    fastIO

    int t;
    cin >> t;
    while (t--) {
        vector<pair<int ,int>>p;
        int n,steps=0,k=0;
        cin>>n;
        int n2=n;
        while(n2>2){
            n2 = ceil(sqrt(n2));
            for(int i=n2+1;i<n;i++){
                p.push_back(make_pair(i,n));
                steps++;
            }
            p.push_back(make_pair(n,n2));
            p.push_back(make_pair(n,n2));
            n = n2 ;
            steps+=2;
        }
        cout<<steps<<E;
        
        for(auto it:p)cout<<it.first<<S<<it.second<<E;

    }

    return 0;
}