#include <bits/stdc++.h>
using namespace std;
#define int long long
#define quickread                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define hii cout << "Hii there Sparky! \n"
#define endl '\n'
#define mod 1000000007
#define maxn 100010

void solve() {
    float n;
    cin >> n;
    int n2 = n;
    vector<pair<int, int>> ans;
    float x = n - 1;
    while (x > 1) {
        float a = ceil(n / x);
        if (a >= x && a >= 2) {
            n = ceil(n / x);
            ans.pb({n2, x});
        }
        if (x == 2 && n > 2) {
            ans.pb({n2, 2});
        }
        ans.pb({x, n2});
        x--;
    }
    cout << ans.size() << endl;
    for (auto x : ans) {
        cout << x.first << " " << x.second << endl;
    }
}

int32_t main() {
    quickread;
    int test = 1;
    cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}