#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int x, y, z;
};
int main() {
  long long int t, i;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    if (n == 2) {
      cout << 2 << endl;
      cout << 1 << " " << 2 << endl;
      continue;
    }
    cout << 2 << endl;
    cout << n << " " << n - 2 << endl;
    cout << n - 1 << " " << n - 1 << endl;
    long long int cnt = n - 1;
    for (i = 1; i < n - 2; i++) {
      cout << cnt << " " << cnt - 2 << endl;
      cnt--;
    }
  }
}
