#include<iostream>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
void solve(){
	ll n;cin>>n;
	if(n==1){
		cout<<0<<endl;
		cout<<1<<endl;
		cout<<0<<endl;
		return;
	}
	ll ans=0;
	ll cnt=1,st=n-1,asz=0;
	while(asz<n-1){
		if(cnt==0){
			cnt=2;
			st--;
		}
		ans+=st*st;
		cnt--;
		asz++;
	}
	cout<<ans<<endl;
	vector<ll> p;
	vector<ll> opi,opj;
	
	p.push_back(n/2+1);
	for(int i=1;i<n/2;i++) p.push_back(i);
	for(int i=n/2+2;i<=n;i++) p.push_back(i);
	p.push_back(n/2);
	for(int i=n/2+1;i<n;i++){
		opi.push_back(i);
		opj.push_back(1);
	}
	for(int i=n/2;i>1;i--){
		opi.push_back(i);
		opj.push_back(n);
	}
	if(n!=1){
		opi.push_back(1);
		opj.push_back(n);
	}
	
	for(int i=0;i<p.size();i++){
		cout<<p[i]<<" ";
	}
	cout<<endl;
	cout<<opi.size()<<endl;
	for(int j=0;j<opi.size();j++){
		cout<<opi[j]<<" "<<opj[j]<<endl;
	}
	cout<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;cin>>t;
	while(t--) solve();
	return 0;
}