//
//  main.cpp
//  edu codeforces 101 A
//
//  Created by Joshua Koo on 12/28/20.
//
 
#include <stdio.h>
#include <algorithm>
#include <limits.h>
#include <map>
#include <set>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <set>
#include <string.h>
FILE *in = stdin;
FILE *out = stdout;
using namespace std;
int t;
int main() {
    fscanf(in, "%d", &t);
    for (int cases = 1; cases <= t; cases++) {
        int n;
        fscanf(in, "%d", &n);
        vector<double> v;
        map<double, int> m;
        int ans;
        int cnt = 0;
        double current = (double)n;
        while (current >= 2) {
            v.push_back(current);
            cnt++;
            m[current] = 1;
            if (current == 2) break;
            current = ceil(sqrt(current));
        }
        m[1] = 1;
        v.push_back(1);
        cnt++;
        ans = n - cnt;
        for (int i = 2; i <= v.size() - 1; i++) {
            ans += 2;
        }
        fprintf(out, "%d\n", ans);
        for (double i = 1; i <= n; i++) {
            if (m[i] == 0) {
                fprintf(out, "%d %d\n", (int)i, (int)i + 1);
            }
        }
        for (int i = 0; i < v.size() - 2; i++) {
            fprintf(out, "%d %d\n%d %d\n", (int)v[i], (int)v[i+1], (int)v[i], (int)v[i+1]);
        }
    }
    return 0;
}
