#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define SIZE 500000
using namespace std;
typedef long long ll;
const ll INF = 1e10;
ll t = 1, n, m, k;
ll temp;
string s;
ll arr[SIZE];


int main() {
    fast;
    cin >> t;
    while (t--) {
        cin >> n;
        vector<ll> special;
        ll curr = n;
        while (curr > 2) {
            special.push_back(ceil(curr));
            curr = ceil(sqrt(curr));
        }
        vector<pair<ll, ll>> res;
        for (int i = 3; i <= n - 1; ++i) {
            bool found = false;
            for (auto j : special) if (j == i) found = true;
            if (!found) res.push_back({i, n});
        }
        sort(special.begin(), special.end());
        for (int i = special.size() - 1; i >= 1; --i) {
            res.push_back({special[i], special[i - 1]});
            res.push_back({special[i], special[i - 1]});
        }
        res.push_back({special[0], 2});
        res.push_back({special[0], 2});
        cout << res.size() << "\n";
        for (auto p : res) cout << p.first << " " << p.second << "\n";
    }
}

