#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long n, i;
    cin >> n;
    if (n == 2) {
      cout << 2 << "\n";
      cout << "1 2";
      cout << endl;
      continue;
      ;
    }
    vector<long long> a(n, 0);
    for (long long i = 0; i < n; i++) {
      a[i] = i + 1;
    }
    reverse(a.begin(), a.end());
    pair<long long, long long> p[n - 1];
    for (i = 0; i < n - 1; i++) {
      long long x = a[i], y = a[i + 1];
      if ((x + y) % 2) {
        a[i + 1] = (x + y) / 2 + 1;
      } else {
        a[i + 1] = (x + y) / 2;
      }
      a[i] = 0;
      p[i].first = x, p[i].second = y;
    }
    cout << a[n - 1];
    cout << endl;
    ;
    for (i = 0; i < n - 1; i++) {
      cout << p[i].first << " " << p[i].second;
      cout << endl;
      ;
    }
  }
}
