#include<iostream>
using namespace std;
int main(){
int b;
while(cin>>b){
for(int k=0;k<b;k++){
char a[1024];
gets(a);
int c=0;
int cnt[26]={};
for(int i=0;a[i];i++){
if(a[i]>='a'&&a[i]<='z')
cnt[a[i]-'a']++;
else if(a[i]>='A'&&a[i]<='Z')
cnt[a[i]-'A']++;
}
for(int j=0;cnt[j];j++){
if(cnt[j]>c)
c=cnt[j];
}
for(int j=0;j<26;j++){
if(cnt[j]==c)
printf("%c",'a'+j);
}
}
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCl7CmludCBiOwp3aGlsZShjaW4+PmIpewoJZm9yKGludCBrPTA7azxiO2srKyl7CgljaGFyIGFbMTAyNF07CglnZXRzKGEpOwoJaW50IGM9MDsKCWludCBjbnRbMjZdPXt9OwoJZm9yKGludCBpPTA7YVtpXTtpKyspewoJaWYoYVtpXT49J2EnJiZhW2ldPD0neicpCgljbnRbYVtpXS0nYSddKys7CgllbHNlIGlmKGFbaV0+PSdBJyYmYVtpXTw9J1onKQoJCWNudFthW2ldLSdBJ10rKzsKCX0KCWZvcihpbnQgaj0wO2NudFtqXTtqKyspewoJaWYoY250W2pdPmMpCgkJYz1jbnRbal07Cgl9Cglmb3IoaW50IGo9MDtqPDI2O2orKyl7CglpZihjbnRbal09PWMpCglwcmludGYoIiVjIiwnYScraik7Cgl9CgkKCX0KfQogIHJldHVybiAwOwp9