#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    multiset<int, greater<int>> elements;
    for (int i = 1; i <= n; i++) {
      elements.insert(i);
    }
    cout << "2\n";
    vector<pair<int, int>> ans;
    while (elements.size() > 2) {
      auto it = elements.begin();
      int f = *it;
      it++;
      int s = *it;
      it++;
      int t = *it;
      if ((f + s) % 2 == 0) {
        ans.push_back(make_pair(f, s));
        elements.erase(elements.begin());
        elements.erase(elements.begin());
        elements.insert((f + s) / 2);
      } else {
        ans.push_back(make_pair(f, t));
        elements.erase(elements.begin());
        auto it = elements.begin();
        it++;
        elements.erase(it);
        elements.insert((f + t) / 2);
      }
    }
    int f = *elements.begin();
    elements.erase(elements.begin());
    int s = *elements.begin();
    ans.push_back(make_pair(f, s));
    for (auto x : ans) {
      cout << x.first << " " << x.second << endl;
    }
  }
  return 0;
}
