#include <bits/stdc++.h>
using namespace std;
void fun() {
  int n;
  cin >> n;
  if (n == 2) {
    cout << 2 << "\n" << 1 << " " << 2;
    return;
  }
  int nr = n;
  int curr = 0;
  map<int, int> m;
  vector<int> v;
  int currans;
  while (nr > 1) {
    if (curr == 0) {
      v.push_back(n);
      v.push_back(n - 2);
      currans = n - 1;
      m[n]++;
      m[n - 2]++;
      n--;
      curr += 1;
      nr--;
    } else {
      if (m[n] == 0) {
        v.push_back(n);
        v.push_back(n);
        currans = n;
        curr = 0;
        nr--;
      } else {
        curr = 0;
      }
    }
  }
  cout << currans << endl;
  for (int i = 0; i < v.size(); i += 2) {
    cout << v[i] << " " << v[i + 1] << endl;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    fun();
    cout << endl;
  }
}
