#include <bits/stdc++.h>
struct pairs {
  int a;
  int b;
};
int main() {
  using namespace std;
  int t, n, i, o, s;
  cin >> t;
  while (t--) {
    cin >> n;
    s = n;
    vector<int> a(n);
    vector<pairs> answer(n - 1);
    for (i = 1; i <= n; i++) {
      a[i - 1] = i;
    }
    for (o = 0; o < n - 1; o++) {
      for (i = s - 2; i >= 0; i--) {
        if (a[s - 1] % 2 == a[i] % 2) {
          answer[o].a = a[i];
          answer[o].b = a[s - 1];
          a.erase(a.begin() + i);
          s--;
          a.erase(a.begin() + s - 1);
          a.push_back((answer[o].a + answer[o].b) / 2);
          break;
        }
      }
    }
    cout << a[s - 1] << endl;
    if (n == 2)
      cout << 2 << ' ' << 1 << endl;
    else {
      for (pairs pair : answer) {
        cout << pair.a << ' ' << pair.b << endl;
      }
    }
  }
  return 0;
}
