#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long t, n, m, i, k;
long long a[1000005];
vector<long long> v;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    cout << "2\n";
    if (n > 3) {
      v.push_back(n);
      v.push_back(n - 2);
      v.push_back(n - 1);
      v.push_back(n - 1);
      i = n - 1;
      while (i > 2) {
        v.push_back(i);
        v.push_back(i - 2);
        i--;
      }
      for (i = 0; i < v.size(); i += 2) {
        cout << v[i] << " " << v[i + 1] << "\n";
      }
    } else {
      if (n == 2)
        cout << "1 2\n";
      else {
        cout << "3 1\n2 2\n";
      }
    }
    v.clear();
  }
  return 0;
}
