#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (long long)((1e5) + 100);
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
void prl(long long x) { cout << x << "\n"; }
const long long N = (long long)(1 * 1e6 + 10);
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) a[i] = i + 1;
    sort(a, a + n, greater<long long>());
    long long ans = (a[0] + a[1] + 1) / 2;
    for (long long i = 2; i < n; i++) {
      ans = (ans + a[i] + 1) / 2;
    }
    prl(ans);
    cout << a[0] << " " << a[1] << "\n";
    ans = (a[0] + a[1] + 1) / 2;
    for (long long i = 2; i < n; i++) {
      cout << a[i] << " " << ans << "\n";
      ans = (ans + a[i] + 1) / 2;
    }
  }
}
