#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  if (n == 2) {
    cout << "2\n1 2\n";
  } else if (n == 3) {
    cout << "2\n1 3\n2 2\n";
  } else {
    int a, b, c;
    a = n - 1;
    b = n - 3;
    cout << "2\n";
    cout << n << ' ' << n - 2 << '\n';
    cout << n - 1 << ' ' << n - 1 << '\n';
    while (b != 1) {
      cout << a << ' ' << b << '\n';
      a = a - 1;
      b = b - 1;
    }
    cout << a << ' ' << b << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
