#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, less<int> > Q;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int ans[maxn * 2][2];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    while (!Q.empty()) Q.pop();
    for (int i = 1; i <= n; i++) Q.push(i);
    int cnt = 0;
    int k = n - 1;
    while (k--) {
      int top1 = Q.top();
      Q.pop();
      int top2 = Q.top();
      Q.pop();
      if ((top1 + top2) % 2 == 1) {
        Q.push((top1 + top2 + 1) / 2);
        ans[cnt][0] = top1;
        ans[cnt++][1] = top2;
      } else {
        Q.push((top1 + top2) / 2);
        ans[cnt][0] = top1;
        ans[cnt++][1] = top2;
      }
    }
    cout << Q.top() << endl;
    for (int i = 0; i < cnt; i++) {
      cout << ans[i][0] << " ";
      cout << ans[i][1] << " ";
      cout << endl;
    }
  }
  return 0;
}
