#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    deque<long long> vc;
    for (int i = 1; i <= n; i++) {
      vc.push_back(i);
    }
    long long big = n;
    vector<pair<long long, long long> > ans;
    for (int i = 1; i <= n - 1; i++) {
      long long f = vc.back();
      vc.pop_back();
      long long l = vc.back();
      vc.pop_back();
      ans.push_back({f, l});
      big = (f + l + 1) / 2;
      vc.push_back(big);
    }
    cout << big << "\n";
    for (auto tp : ans) cout << tp.first << " " << tp.second << endl;
  }
  return 0;
}
