// Problem: D. Ceil Divisions
// Contest: Codeforces - Educational Codeforces Round 101 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1469/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define x first
#define y second
#define sf scanf
#define pf printf
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
#define debug(x) cout << #x << ": " << x << endl;
const int MOD = 998244353;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, 1, -1};
const int dz[] = {1, -1, 0, 0, 0, 0 };
int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll n;
ll a[maxn],b[maxn],c[maxn];
void solve()
{
cin>>n;
ll cnt=0;
ll ans=n;
for(int i=n-1;i>2;i--){
if(ans/i>=i){
if(ans%i==0){
ans=ans/i;
}else ans=ans/i+1;
b[++cnt]=n;
c[cnt]=i;
}
b[++cnt]=i;
c[cnt]=n;
}
while(ans>=2)
{
if(ans%2==0)
ans/=2;
else
ans=ans/2+1;
b[++cnt]=n;
c[cnt]=2;
}
cout<<cnt<<endl;
for(int i=1;i<=cnt;i++){
cout<<b[i]<<" "<<c[i]<<endl;
}
}
int main()
{
ll t = 1;
scanf("%lld",&t);
while(t--)
{
solve();
}
return 0;
}