#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n];
    for (int i = 0; i < n; i++) {
      arr[i] = i + 1;
    }
    cout << 2 << endl;
    for (int i = n - 2; i >= 0; i--) {
      double sum = (arr[i] + arr[i + 1]) / 2.0;
      int int_sum = (arr[i] + arr[i - 1]) / 2;
      if (sum - int_sum >= 0.5) {
        cout << arr[i] << " " << arr[i + 1] << endl;
        arr[i] = ceil(sum);
      } else {
        cout << arr[i] << " " << arr[i + 1] << endl;
        arr[i] = int_sum;
      }
    }
  }
}
