#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n+1];
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=n/2-1;i>=1;i--){
if(a[i]==a[i+1] || a[n-i+1]==a[n-i]){
swap(a[i],a[n-i+1]);
}
}
for(int i=1; i<=n; ++i) cout << a[i] << ' ';
cout << '\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCl7CiAgICBpbnQgdDsKICAgIGNpbj4+dDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgaW50IG47CiAgICAgICAgY2luPj5uOwogICAgICAgIGludCBhW24rMV07CiAgICAgICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgICAgICBjaW4+PmFbaV07CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaT1uLzItMTtpPj0xO2ktLSl7CiAgICAgICAgICAgIGlmKGFbaV09PWFbaSsxXSB8fCBhW24taSsxXT09YVtuLWldKXsKICAgICAgICAgICAgICAgIHN3YXAoYVtpXSxhW24taSsxXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yKGludCBpPTE7IGk8PW47ICsraSkgY291dCA8PCBhW2ldIDw8ICcgJzsgCiAgICAgICAgY291dCA8PCAnXG4nOwogICAgfQp9