#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    long long N;
    cin >> N;
    priority_queue<long long> pq;
    for (long long i = 1; i <= N; ++i) pq.push(i);
    vector<pair<long long, long long>> ans;
    while (pq.size() > 1) {
      long long a = pq.top();
      pq.pop();
      long long b = pq.top();
      pq.pop();
      ans.push_back({a, b});
      pq.push((a + b + 1) / 2);
    }
    cout << pq.top() << endl;
    for (auto it : ans) cout << it.first << " " << it.second << endl;
  }
}
