#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[1000000], i;
    for (i = 0; i < n; i++) a[i] = i + 1;
    int m = n;
    int b[1000000];
    for (i = 0; i < m; i++) b[i] = i + 1;
    while (n > 1) {
      if ((a[n - 2] + a[n - 1]) % 2 != 0)
        a[n - 2] = (a[n - 2] + a[n - 1] + 1) / 2;
      else
        a[n - 2] = (a[n - 2] + a[n - 1]) / 2;
      n--;
    }
    cout << a[0] << endl;
    while (m > 1) {
      cout << b[m - 2] << " " << b[m - 1] << endl;
      if ((b[m - 2] + b[m - 1]) % 2 != 0)
        b[m - 2] = (b[m - 2] + b[m - 1] + 1) / 2;
      else
        b[m - 2] = (b[m - 2] + b[m - 1]) / 2;
      m--;
    }
  }
}
