#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int c = 1; c <= n - 3; c++) v.push_back(c);
    v.push_back(n - 1);
    cout << '2' << endl;
    if (n == 2)
      cout << '1' << ' ' << 2 << endl;
    else {
      int r = (n + (n - 2)) / 2;
      cout << n << ' ' << n - 2 << endl;
      for (int c = v.size() - 1; c >= 0; c--) {
        cout << v[c] << ' ' << r << endl;
        r = (v[c] + r) / 2;
      }
    }
  }
  return 0;
}
