6ms
#include <iostream>
// #include <unordered_set>
#include <cstring>
using namespace std;
const int N = 50;
const int M = 1010;
int a[N];
int b[N];
int c[M];
int main()
{
int T;
cin >> T;
while (T -- )
{
int n;
cin >> n;
memset(c, 0, sizeof (c));
for (int i = 0; i < n; i ++ ) cin >> a[i];
int t = 0;
for (int i = n - 1; i >= 0; i -- )
if (c[a[i]] == 0)
{
c[a[i]] ++ ;
b[t ++ ] = a[i];
}
cout << t << endl;
for (int i = t - 1; i >= 0 ; i -- ) cout << b[i] << ' ';
cout << endl;
}
return 0;
}