#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& t) {
  t = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  t *= f;
}
void TEST() { cout << "OK!!!" << endl; }
const int dx[4] = {1, -1, 1, -1};
const int dy[4] = {-1, 1, 1, -1};
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-5;
const int maxn = 2e5 + 100;
int n, m;
priority_queue<int> q;
int main() {
  int t;
  read(t);
  while (t--) {
    read(n);
    for (int i = 1; i <= n; i++) q.push(i);
    cout << 2 << endl;
    while (q.size() > 1) {
      int a = q.top();
      q.pop();
      int b = q.top();
      q.pop();
      int tmp = (a + b) * 1.0 / 2 + 0.5;
      q.push(tmp);
      cout << a << " " << b << endl;
    }
    q.pop();
  }
  return 0;
}
