#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution {
public:
string FirstNonRepeating(string A){
map<char, int> m;
string ans = "";
queue<char> q;
for(int i=0; i<A.length(); i++) {
char ch = A[i];
q.push(ch);
m[ch]++;
while(!q.empty()) {
if(m[q.front()] > 1){
q.pop();
}
else
{
ans.push_back(q.front());
break;
}
}
if(q.empty()){
ans.push_back('#');
}
}
return ans;
}
};
// { Driver Code Starts.
int main(){
int tc;
cin >> tc;
while(tc--){
string A;
cin >> A;
Solution obj;
string ans = obj.FirstNonRepeating(A);
cout << ans << "\n";
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiAvLyB9IERyaXZlciBDb2RlIEVuZHMKY2xhc3MgU29sdXRpb24gewoJcHVibGljOgoJCXN0cmluZyBGaXJzdE5vblJlcGVhdGluZyhzdHJpbmcgQSl7CgkJICAgIG1hcDxjaGFyLCBpbnQ+IG07CgkJICAgIHN0cmluZyBhbnMgPSAiIjsKCQkgICAgcXVldWU8Y2hhcj4gcTsKCQkgICAgCgkJICAgIGZvcihpbnQgaT0wOyBpPEEubGVuZ3RoKCk7IGkrKykgewoJCSAgICAgICAgY2hhciBjaCA9IEFbaV07CgkJICAgICAgICAKCQkgICAgICAgIHEucHVzaChjaCk7CgkJICAgICAgICBtW2NoXSsrOwoJCSAgICAgICAgCgkJICAgICAgICB3aGlsZSghcS5lbXB0eSgpKSB7CgkJICAgICAgICAgICAgaWYobVtxLmZyb250KCldID4gMSl7CgkJICAgICAgICAgICAgICAgIHEucG9wKCk7CgkJICAgICAgICAgICAgfQoJCSAgICAgICAgICAgIGVsc2UKCQkgICAgICAgICAgICB7CgkJICAgICAgICAgICAgICAgIGFucy5wdXNoX2JhY2socS5mcm9udCgpKTsKCQkgICAgICAgICAgICAgICAgYnJlYWs7CgkJICAgICAgICAgICAgfQoJCSAgICAgICAgfQoJCSAgICAgICAgaWYocS5lbXB0eSgpKXsKCQkgICAgICAgICAgICBhbnMucHVzaF9iYWNrKCcjJyk7CgkJICAgICAgICB9CgkJICAgIH0KCQkgICAgcmV0dXJuIGFuczsKCQl9Cgp9OwoKLy8geyBEcml2ZXIgQ29kZSBTdGFydHMuCmludCBtYWluKCl7CglpbnQgdGM7CgljaW4gPj4gdGM7Cgl3aGlsZSh0Yy0tKXsKCQlzdHJpbmcgQTsKCQljaW4gPj4gQTsKCQlTb2x1dGlvbiBvYmo7CgkJc3RyaW5nIGFucyA9IG9iai5GaXJzdE5vblJlcGVhdGluZyhBKTsKCQljb3V0IDw8IGFucyA8PCAiXG4iOwoJfQoJcmV0dXJuIDA7Cn0g