#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ans = (n + 1) / 2;
    vector<pair<long long, long long> > fin;
    long long curr = n;
    long long cnt = 0, chk = n - 1;
    while (cnt != n - 1) {
      fin.push_back({curr, chk});
      curr = (curr + chk + 1) / 2;
      chk--;
      cnt++;
    }
    cout << curr << '\n';
    for (auto i : fin) cout << i.first << " " << i.second << '\n';
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
