#include <bits/stdc++.h>
using namespace std;
void f(int arr[], int n) {
  cout << "2" << endl;
  int l, r;
  int f, s;
  f = arr[n - 1 - 2];
  s = arr[n - 1];
  int avg;
  float sum = f + s;
  sum /= 2;
  avg = ceil(sum);
  cout << f << " " << s << endl;
  arr[n - 1 - 2] = avg;
  l = n - 1 - 2;
  r = n - 1 - 1;
  int count = 0;
  for (count = 0; count < n - 2; count++) {
    f = arr[l];
    s = arr[r];
    cout << f << " " << s << endl;
    sum = f + s;
    sum /= 2;
    avg = ceil(sum);
    arr[l] = avg;
    l--;
    r--;
  }
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int arr[n];
    for (int j = 0; j < n; j++) {
      arr[j] = (j + 1);
    }
    if (n == 2) {
      cout << "2" << endl;
      cout << "1 2" << endl;
    } else {
      f(arr, n);
    }
  }
  return 0;
}
