#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n == 1) {
      cout << "1\n";
      continue;
    }
    multiset<int> a;
    for (int i = 1; i <= n; i++) {
      a.insert(i);
    }
    cout << "2\n";
    while (a.size() > 2) {
      auto c = prev(a.end()), b = prev(a.end(), 2);
      if (*b % 2 != *c % 2) b--;
      cout << *c << " " << *b << "\n";
      a.insert((*c + *b + 1) / 2);
      a.erase(c);
      a.erase(b);
    }
    cout << *prev(a.end()) << " " << *a.begin() << "\n";
  }
  return 0;
}
