#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

ll n;

void solve(){
  cin >> n;
  vector<pair<ll, ll>> ans;
  while (n > 2) {
    ll c = ceil(sqrt(n));
    for (ll i = c + 1; i < n; i++) ans.push_back({i, i + 1});
    ans.push_back({n, c});
    ans.push_back({n, c});
    n = c;
  }
  cout << ans.size() << endl;
  for (auto i : ans) cout << i.first << ' ' << i.second << endl;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll t = 1;
  // cout << "\n\nBLAH BLAH BLAH\n\n";
  cin >> t;
  while(t--){
    solve();
  }
  return 0;
}