#include<stdio.h> #include<string.h> #include<string> #include<math.h> #include<stdlib.h> #include<algorithm> #include<iostream> using namespace std; int main() { int t,i,j; scanf("%d",&t); while(t--) { string s1,s2,s3; cin>>s1; s2=s1; int ma=0; int len=s1.size(); reverse(s2.begin(),s2.end()); for(i=0; i<len; i++) { for(j=1; j<=len-i; j++) { string::size_type pos=s2.find(s1.substr(i,j)); if(pos!=string::npos&&ma<j) { ma=j; s3=s1.substr(i,j); } } } cout<<s3<<endl; } }