#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TEST;
  cin >> TEST;
  while (TEST--) {
    long long n, i, n1, n2;
    cin >> n;
    vector<pair<long long, long long> > v;
    priority_queue<long long> pq;
    for (long long i = 1; i <= n; i++) pq.push(i);
    i = 1;
    while (i <= n - 1) {
      n1 = pq.top();
      pq.pop();
      n2 = pq.top();
      pq.pop();
      v.push_back(make_pair(n1, n2));
      pq.push((n1 + n2 + 1) / 2);
      i++;
    }
    cout << pq.top() << "\n";
    for (auto i : v) {
      cout << i.first << " " << i.second << "\n";
    }
  }
  return 0;
}
