
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void do_test()
{
    int n;
    cin>>n;
    long long s=0;
    const int m=n/2;
    for (int i=2; i<=m; ++i)
    {
        long long r = n-i;
        r *= r;
        s += r;
    }
    for (int i=m+1; i<=n; ++i)
    {
        long long r = i-1;
        r *= r;
        s += r;
    }
    
    cout << s << "\n";
    
    cout << m+1 << " ";
    for (int i=1; i<=m-1; ++i)
    {
        cout << i << " ";
    }

    for (int i=m+2; i<=n; ++i)
    {
        cout << i << " ";
    }
    cout << m << "\n";

    cout << n-1 << "\n";

    for (int i=m; i>1; --i)
    {
        cout << i << " " << n << "\n";
    }

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


//    1 2 3 4 5 6 7 8 9
//    x x x x x x x x x
//    6 1 2 3 4 7 8 9 5

}

int main()
{
    ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    
    int t;
    cin >> t;

    for (int i=0; i<t; ++i)
    {
        do_test();
    }
}
