#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > vp;
vector<long long> v;
set<long long> st;
long long ara[500005];
map<string, long long> mp;
long long Set(long long N, long long pos) { return N = N | (1LL << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }
vector<long long> e, o;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, n, i, j, p;
  cin >> t;
  while (t--) {
    cin >> n;
    v.clear(), vp.clear();
    for (i = 0; i < n; i++) v.push_back(i + 1);
    long long a = n;
    for (i = n - 1; i >= 0; i--) {
      vp.push_back({a, i});
      a = (a + i + 1) / 2;
    }
    cout << 2 << endl;
    for (i = 0; i < n - 1; i++)
      cout << vp[i].first << " " << vp[i].second << endl;
  }
}
