#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define dwn(i,x,y) for(int i=x;i>=y;i--)
#define ll long long
using namespace std;
template<typename T>inline void qr(T &x){
x=0;int f=0;char s=getchar();
while(!isdigit(s))f|=s=='-',s=getchar();
while(isdigit(s))x=x*10+s-48,s=getchar();
x=f?-x:x;
}
int cc=0,buf[31];
template<typename T>inline void qw(T x){
if(x<0)putchar('-'),x=-x;
do{buf[++cc]=int(x%10);x/=10;}while(x);
while(cc)putchar(buf[cc--]+'0');
}
const int N=31;
int a[N],b[N];
int bijiao(){
int i=1,j=1;
while(i<=24&&j<=24){
if(a[i]==b[j]||a[i]==30||b[j]==30)i++,j++;
else if(a[i]==31&&b[j]==32)i++;
else if(b[j]==31&&a[i]==32)j++;
else if(a[i]==31&&b[j]>=33)j++;
else if(b[j]==31&&a[i]>=33)i++;
else if(a[i]>b[j])j++;
else i++;
}
return i==25&&j<=24;
}
int calc(){
int ans=0;
rep(i,1,23)rep(j,i+1,24){
swap(b[i],b[j]);
ans+=bijiao();
swap(b[i],b[j]);
}
return ans;
}
void solve(){
rep(i,1,24)qr(a[i]);
rep(i,1,24)b[i]=a[i];
int cnt=calc();
random_device rd;
mt19937 g(rd());
int cnt=0;
while(cnt<23*12){
cnt++;
if(cnt%100==0){
shuffle(b+1,b+25,g);
cnt=calc();
}
else{
int i,j;
i=rand()%24+1,j=rand()%24+1;
swap(b[i],b[j]);
int t=calc();
if(t>cnt)cnt=t;
else swap(b[i],b[j]);
}
}
rep(i,1,24)qw(b[i]),putchar(' ');
puts("");
}
int main(){
srand(time(0));
int tt;qr(tt);
while(tt--)solve();
return 0;
}