#include <bits/stdc++.h>

#define int long long

using namespace std;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#define dbm(...) false
#define dbs(...) false
#define dbas(...) false
#endif

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

    int T;
    cin >> T;

    while(T--)
    {
    	int N;
    	cin >> N;

        if(N == 2)
        {
            cout << "1" << '\n';
            cout << "2 1" << '\n';
            cout << "1" << '\n';
            cout << "2 1" << '\n';
            continue;
        }
        if(N == 3)
        {
            cout << "5" << '\n';
            cout << "2 3 1" << '\n';
            cout << "2" << '\n';
            cout << "1 3" << '\n';
            cout << "3 2" << '\n';
            continue;
        }

    	vector<int> vect;

        int sz1 = (N-2)/2;
        int sz2 = (N-2)-sz1;

        vect.push_back(1+sz1+1);

        for(int i = 3 ; i <= 1+sz1 ; i++)
        {
            vect.push_back(i);
        }

        vect.push_back(1);

        for(int i = 1+sz1+2 ; i <= N ; i++)
        {
            vect.push_back(i);
        }

        vect.push_back(2);

        int sum = 0;

        for(int i = 1, ppp = N-2 ; i <= sz1 ; i++, ppp--)
        {
            sum += ppp*ppp;
        }  

        for(int i = 1, ppp = N-2 ; i <= sz2 ; i++, ppp--)
        {
            sum += ppp*ppp;
        }  

        sum += (N-1)*(N-1);

        cout << sum << '\n';

        for(auto x : vect)
        {
            cout << x << " ";
        }
        cout << '\n';

        cout << N-1 << '\n';

        for(int i = 1 ; i <= sz1 ; i++)
        {
            cout << i+1 << " " << N << '\n';
        }

        for(int i = 1 ; i <= sz2 ; i++)
        {
            cout << sz1+1+i << " " << 1 << '\n';
        }

        cout << 1 << " " << N << '\n';
    }

    return 0;
}