#include<bits/stdc++.h>
using namespace std;
int ok = 1;
void result(int n, int x[]){
for(int i = 1; i <= n;i++){
cout << x[i];
}cout << " ";
}
void next(int n, int x[]){
int j = n-1;
while(j > 0 && x[j] > x[j+1]){
j--;
}
if(j>0){
int k = n;
while(x[j] > x[k])k--;
int t = x[j];x[j]= x[k];x[k]=t;
int r = n, l = j + 1;
while(l <= r){
t = x[l];
x[l]= x[r];
x[r]= t;
l++;r--;
}
}
else ok = 0;
}
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int x[100];
for(int i = 1; i <= n;i++){
x[i] = i;}
ok = 1;
while(ok){
result(n,x);
next(n,x);
}
cout << endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG9rID0gMTsKdm9pZCByZXN1bHQoaW50IG4sIGludCB4W10pewoJZm9yKGludCBpID0gMTsgaSA8PSBuO2krKyl7CgkJY291dCA8PCB4W2ldOwoJfWNvdXQgPDwgIiAiOwp9CnZvaWQgbmV4dChpbnQgbiwgaW50IHhbXSl7CglpbnQgaiA9IG4tMTsKCXdoaWxlKGogPiAwICYmIHhbal0gPiB4W2orMV0pewoJCWotLTsKCX0KCWlmKGo+MCl7CgkJaW50IGsgPSBuOwoJCXdoaWxlKHhbal0gPiB4W2tdKWstLTsKCQlpbnQgdCA9IHhbal07eFtqXT0geFtrXTt4W2tdPXQ7CgkJaW50ICByID0gbiwgbCA9IGogKyAxOwoJCXdoaWxlKGwgPD0gcil7CgkJCXQgPSB4W2xdOwoJCQl4W2xdPSB4W3JdOwoJCQl4W3JdPSB0OwoJCQlsKys7ci0tOwoJCX0KCX0KCWVsc2Ugb2sgPSAwOwp9CmludCBtYWluKCl7CglpbnQgdDsKCWNpbiA+PiB0OwoJd2hpbGUodC0tKXsKCQlpbnQgbjsKCQljaW4gPj4gbjsKCQlpbnQgeFsxMDBdOwoJCWZvcihpbnQgaSA9IDE7IGkgPD0gbjtpKyspewoJCQl4W2ldID0gaTt9CgkJb2sgPSAxOwoJCXdoaWxlKG9rKXsKCQkJcmVzdWx0KG4seCk7CgkJCW5leHQobix4KTsKCQl9CgkJY291dCA8PCBlbmRsOwoJfQoJcmV0dXJuIDA7Cn0=