#include<cstring>
#include<cstdio>
using namespace std;
int main() {
int cases;
scanf("%d", &cases);
while (cases--) {
int N;
scanf("%d", &N);
bool data[100000];
memset(data,0,sizeof(data));
int max =0;
for (int i = 0; i < N * N; ++i) {
int temp;
scanf("%d", &temp);
data[temp] = 1;
if(max<temp)
max =temp;
}
for(int i = 0; i<= max; ++i){
if(data[i])
cout<<i<<" ";
}
}
return 0;
}