#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define REP(i,a,b) for(int i = a; i < b; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;


void solve(){
	int n; cin >> n;
    vector<pi> opt;
    int x = n;
    while(x > 2) {
        int y = (int)ceil(sqrt(x));
        REP(i,y+1,x) opt.PB({i,x});
        opt.PB({x,y});
        opt.PB({x,y});
        x = y;
    }
    cout << opt.size() << endl;
    for(auto& p : opt) cout << p.first << ' ' << p.second << endl;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; cin >> t;
    while(t--) solve(); 
}
