#include <bits/stdc++.h>
using namespace std;
long long int B[5000000];
int main() {
  long long int a, b, c, d, e, i, j, k, t, n, x;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int A[n + 6];
    cout << "2" << endl;
    if (n == 2) {
      cout << "1"
           << " "
           << "2" << endl;
      continue;
    }
    for (i = 1; i <= n; i++) {
      A[i] = i;
    }
    k = (A[n - 1] + A[n]);
    if (k % 2 != 0) k++;
    k = k / 2;
    B[0] = A[n - 1];
    B[1] = A[n];
    cout << B[0] << " ";
    cout << B[1] << endl;
    A[n - 1] = k;
    n--;
    b = 2;
    a = 0;
    c = 2;
    while (1) {
      i = n, j = n - 1;
      B[c++] = A[n - 1];
      cout << B[c - 1] << " ";
      B[c++] = A[n];
      cout << B[c - 1] << endl;
      A[j] = (A[i] + A[j]) / 2;
      n--;
      if (n == 1) break;
    }
  }
  return 0;
}
