#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  priority_queue<long long> pq;
  vector<pair<long long, long long> > A;
  for (long long i = 1; i <= n; i++) {
    pq.push(i);
  }
  while (pq.size() > 1) {
    long double x = pq.top();
    pq.pop();
    long double y = pq.top();
    pq.pop();
    A.push_back({x, y});
    pq.push(ceil((x + y) / 2));
  }
  cout << pq.top() << endl;
  for (pair<long long, long long> x : A) {
    cout << x.first << " " << x.second << endl;
  }
}
int main() {
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    solve();
  }
}
