#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int m = n;
    int k = n;
    n -= 2;
    while (n) {
      k = (k + n) / 2;
      n--;
    }
    cout << k << '\n';
    for (int i = m; i > 1; i--)
      if (i == m)
        cout << i << ' ' << i - 1 << '\n';
      else
        cout << i + 1 << ' ' << i - 1 << '\n';
  }
  return 0;
}
