#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cerr << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}

#define imie(args) cerr << #args << ": "; cerr << args;
// -----------------------------------------------

void solve(int n, vector<pair<int, int>>&ans) {
	if (n == 2)
		return;

	int y = max(1ll, (int)sqrt(n)-1);
	while (y < (n+y-1)/y) {
		y++;
	}
	for (int pos = y+1; pos < n; pos++) {
		ans.emplace_back(pos, n);
	}
	ans.emplace_back(n, y);
	ans.emplace_back(n, y);
	solve(y, ans);
}

signed main(){

    fastIO

    int t;
    cin >> t;
    while (t--) {
    	int n;
    	cin >> n;
    	vector<pair<int, int>> ans;
    	solve(n, ans);
    	cout << (int) ans.size() << "\n";
    	for (auto&it : ans) {
    		cout << it.ff << ' ' << it.ss << "\n";
    	}
    }
    
    return 0;
}