#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int N = (int)(2e5) + 7;
int _, n;
void solve() {
  if (n == 2) {
    printf("2\n1 2\n");
    return;
  }
  printf("2\n");
  printf("%d %d\n", n, n - 2);
  printf("%d %d\n", n - 1, n - 1);
  int x = n - 1;
  for (int i = n - 3; i >= 1; --i) {
    printf("%d %d\n", x, i);
    x = (x + i) / 2;
  }
}
int main() {
  for (scanf("%d", &_); _; --_) {
    scanf("%d", &n);
    solve();
  }
  return 0;
}
