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

using namespace std;

void getQuque(int temp)
{
	vector<int> iVec(temp, -1);
	vector<int>::iterator itor;
	int loc = -1, count = 1, countZ = 0;
	while (1)
	{
		if(count >= temp) break;
		while (1)
		{
			if(loc == temp) loc = 0;
			if (iVec[(loc + 1)%temp] != -1)
			{
				++loc;
				if(loc == temp) loc = 0;
			}
			else
			{
				loc++;
				countZ += 1;
				if(loc == temp ) loc = 0;
				if(countZ == 2)
				{
					countZ = 0;
					break;
				}
			}
		}
		iVec[loc] = count;
		++count;
	}
	for (int i = 0; i < temp; ++i)
	{
		if(iVec[i] == -1)
			cout<<count;
		else cout<<iVec[i];
		if (i != temp - 1)   cout<<" ";
	}
}

int main()
{
	int n, temp;
	cin>>n;
	vector<int> nVec;
	for (int i = 0; i < n; ++i)
	{
		cin>>temp;
		nVec.push_back(temp);
	}
	for (int i = 0; i < n; ++i)
	{
		getQuque(nVec[i]);
		if (i != n - 1)   cout<<endl;
	}
	return 0;
}