#include <bits/stdc++.h> 
//#include <atcoder/all>
#define rep(i, n) for(long long int i = 0; i < n; ++i)
#define _rep(i, m, n) for(long long int i = m; i < n; ++i)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
//typedef modint1000000007 mint;
//typedef modint998244353 mint;
using Graph = vector<vector<int>>;
const int inf = 1e9 + 1;
const ll INF = 1e18 + 1;

/*------------------------------------------------------------------*/

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t; cin >> t;

    while(t--){
        int n; cin >> n;
        vector<pair<int,int>> res;
        if(n > 32){
            for(int i = 32; i < n - 1; i++){
                res.push_back({i + 1, n});
            }
            int m = n;
            while(m > 1){
                res.push_back({n, 32});
                m = (m + 31) / 32;
            }
            n = 32;
        }
        for(int i = 2; i <= n - 2; i++){
            res.push_back({i + 1, n});
        }
        for(int i = 1; i <= 5; i++){
            res.push_back({n, 2});
        }
        cout << res.size() << endl;
        for(auto it : res){
            cout << it.first << " " << it.second << endl;
        }
    }
}