#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define mp make_pair
#define fi first
#define se second


ll n;

void init() {
}

void input() {
    cin >> n;
}

ll sq (ll n) {
    ll l = 0, r = n + 1;

    while (l + 1 < r) {
        ll m = (l + r) / 2;

        if (m * m > n) {
            r = m;
        }

        else {
            l = m;
        }
    }

    if (l * l < n) {
        l++;
    }

    return l;
}

void solve() {
    int ans = 0;

    int inst = n;

    while (n > 2) {
        int newn = sq(n);

        ans += n - newn - 1;

        ans += 2;

        n = newn;
    }

    cout << ans << endl;

    n = inst;

    while (n > 2) {
        int newn = sq(n);

        for (int i = newn + 1; i < n; i++) {
            cout << i << ' ' << i + 1 << endl;
        }

        cout << n << ' ' << newn << endl;

        cout << n << ' ' << newn << endl;

        n = newn;
    }
}

void output() {
}

int main()
{
    ios_base::sync_with_stdio(false);

    int number_of_testcases = 1;
    cin >> number_of_testcases;
    while (number_of_testcases--) {
        init();

        input();

        solve();

        output();
    }

    return 0;
}
