#include <bits/stdc++.h>

using namespace std;

#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif

int main() {
      ios_base :: sync_with_stdio(0);
      cin.tie(0);

      int t; cin >> t;
      while (t--) {
            int n; cin >> n;

            vector <pair <int, int>> ans;

            // if (n == 3) {
            //       cout << "2\n3 2\n3 2\n";
            //       continue;
            // }

            if (n <= (1LL << 8)) {
                  for (int i = 3; i <= n - 1; ++i) {
                        ans.push_back({i, i + 1});
                  }
                  int dd = n;
                  while (dd != 1) {
                        ans.push_back({n, 2});
                        dd = (dd + 1) / 2;
                  }

                  cout << (int) ans.size() << '\n'; 
                  for (auto x : ans) cout << x.first << ' ' << x.second << '\n';
            } else {
                  int dd = 64;

                  for (int i = 3; i < 64; ++i) {
                        ans.push_back({i, i + 1});
                  }

                  for (int i = dd + 1; i <= n - 1; ++i) {
                        ans.push_back({i, i + 1});
                  }

                  int ff = n;
                  while (ff != 1) {
                        ans.push_back({n, 64});
                        ff = (ff + 63) / 64;
                  }
                  // am I fucking retarded wow
                  // I legit thought of this but didnt fucking do it

                  // n - 4 + log128(n) + log2(128) -> I guess it's still a bit more than n + 5
                  // let's try 64

                  while (dd != 1) {
                        ans.push_back({64, 2});
                        dd /= 2;
                  }

                  cout << (int) ans.size() << '\n';
                  for (auto& x : ans) cout << x.first << ' ' << x.second << '\n';
            }

            // fucking retard

      }      
}
