#include <bits/stdc++.h>
using namespace std;
void calc(int i, int j, vector<pair<int, int>> &v) {
  v.push_back(make_pair(i, j));
  if (i == 1) {
    cout << (i + j + 1) / 2 << endl;
    return;
  }
  calc(i - 1, (i + j + 1) / 2, v);
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    vector<pair<int, int>> v;
    int n;
    cin >> n;
    calc(n - 1, n, v);
    for (int i = 0; i < v.size(); i++) {
      cout << v[i].first << " " << v[i].second << endl;
    }
  }
}
