#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define rep(x,y) for(int i = x; i <= y; i++)
const int maxn = 1e5 + 5; 
ll tim[maxn];

int main() {
	
	int t,n;
	scanf("%d",&t);
	while(t--) {
		scanf("%d",&n);
		ll ans = 0;
		rep(3,n+1) ans += (ll)(n-i/2)*(n-i/2);
		printf("%lld\n",ans);
		printf("%d ",(n+2)/2);
		rep(1,(n-2)/2) printf("%d ",i);
		rep((n+4)/2,n) printf("%d ",i);
		printf("%d\n",(n)/2);
		printf("%d\n",n-1);
		for(int i = n/2; i > 1; i--) printf("%d %d\n",i,n);
		rep((n)/2+1,n) printf("%d %d\n",i,1);
	}
	return 0;
}