#include <iostream>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
map<int, int> m;
int n;
cin >> n;
for(int i = 0; i < n; i++){
int a;
cin >> a;
m[a]++;
cout << (--m.end())->first << " ";
}
cout << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxtYXA+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpewogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlKHQtLSl7CiAgICAJbWFwPGludCwgaW50PiBtOwogICAgICAgIGludCBuOwogICAgICAgIGNpbiA+PiBuOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICBpbnQgYTsKICAgICAgICAgICAgY2luID4+IGE7CiAgICAgICAgICAgIG1bYV0rKzsKICAgICAgICAgICAgY291dCA8PCAoLS1tLmVuZCgpKS0+Zmlyc3QgIDw8ICIgIjsKICAgICAgICB9CiAgICAgICAgY291dCA8PCBlbmRsOwogICAgfQp9Cg==