#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    priority_queue<int> pq;
    int n, i, k;
    cin >> n;
    for (i = 1; i <= n; i++) pq.push(i);
    k = n - 1;
    vector<pair<int, int>> ans;
    while (k--) {
      int q1 = pq.top();
      pq.pop();
      int q2 = pq.top();
      pq.pop();
      ans.push_back({q1, q2});
      pq.push(ceil((q1 + q2) / 2.0));
    }
    cout << pq.top() << endl;
    for (auto x : ans) {
      cout << x.first << " " << x.second << endl;
    }
  }
}
