#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  double i, j;
  cin >> n;
  vector<long long> a;
  vector<long long> b;
  vector<long long>::iterator it1;
  vector<long long>::iterator it2;
  i = n;
  for (j = n - 1; j >= 1; j--) {
    a.push_back(i);
    b.push_back(j);
    i = round((i + j) / 2);
  }
  cout << i << "\n";
  it1 = a.begin();
  it2 = b.begin();
  while (it1 != a.end() && it2 != b.end()) {
    cout << *it1 << " " << *it2 << "\n";
    it1++;
    it2++;
  }
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
