#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 400100;

int T, n, a[N];
vector < pair <int, int> > res;

int main() {

	scanf("%d", &T);

	for (int t = 1; t <= T; t++) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			a[i] = i + 1;
		}
		int d = min(16, n);
		for (int i = 0; i < n; i++) {
			if (a[i] != 1 && a[i] != 2 && a[i] != d && a[i] != n) {
				res.push_back(make_pair(i + 1, n));
			}
		}
		if (n <= 16) {
			while (a[d - 1] > 1) {
				a[d - 1] = (a[d - 1] + 1) / 2;
				res.push_back(make_pair(d, 2));
			}
		} else {
			while (a[n - 1] > 1) {
				res.push_back(make_pair(n, d));
				a[n - 1] = (a[n - 1] + d - 1) / d;
			}
			while (a[d - 1] > 1) {
				res.push_back(make_pair(d, 2));
				a[d - 1] = (a[d - 1] + 1) / 2;
			}
		}
		printf("%d\n", (int) res.size());
		for (int i = 0; i < res.size(); i++) {
			printf("%d %d\n", res[i].first, res[i].second);
		}
		res.clear();
	}

	return 0;

}