#include <bits/stdc++.h>
using namespace std;
const long long mx = 10000000;
const long long mod = 1e9 + 7;
void solve() {
  int t = 1;
  std ::cin >> t;
  while (t--) {
    int n;
    std ::cin >> n;
    if (n == 2) {
      std ::cout << 2;
      cout << "\n";
      std ::cout << 1 << " " << 2;
      cout << "\n";
      continue;
    }
    int m = n - 2;
    int lop = n;
    std ::cout << 2;
    cout << "\n";
    std ::cout << m-- << " " << n--;
    cout << "\n";
    std ::cout << n << " " << n;
    cout << "\n";
    for (int i = 0; i < lop - 3; i++) {
      std ::cout << m-- << " " << n--;
      cout << "\n";
    }
    cout << "\n";
  }
}
int main() {
  solve();
  return 0;
}
