#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int n1 = n;
       int f[200000 +2]={0,};
        vector<int> temp;
        while (n1 !=2)
        {
            n1 = (int)sqrt(n1) + 1;
           f[n1] = 1;
            temp.push_back(n1); 
         // cout<<n1<<endl;
        }
        vector<pair<int, int>> ans;
        for (int i = n - 1; i > 2; i--)
        {
           if (f[i] == 0)
                ans.push_back(make_pair(i, n));
        }
        ans.push_back(make_pair(n, temp[0]));
        ans.push_back(make_pair(n, temp[0]));

        int p = temp[0];
        for (int i = 1; i < temp.size(); i++)
        {
            ans.push_back(make_pair(p, temp[i]));
            ans.push_back(make_pair(p, temp[i]));
            p=temp[i];
        }
        // if(temp.size() > 1)
        // ans.push_back(make_pair(p, 2));
        cout<<ans.size()<<endl;
        for(int i=0;i<ans.size();i++)
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}