#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
char a[5010],c[5010];
int b[5010];
int main()
{
int s;
scanf("%d",&s);getchar();
while(s--)
{
int max,i,j,t1,t2,len;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
gets(a);
len=strlen(a);
j=0;
for(i=0;i<len;i++)
if(isalpha(a[i]))
{
c[j]=tolower(a[i]);
b[j++]=i;
}
len=j;
max=0;
for(i=0;i<len;i++)
{
for(j=0;i-j>=0&&i+j<len;j++)
{
if(c[i-j]!=c[i+j])
break;
else
{
if(2*j+1>max)
{
max=2*j+1;
t1=i-j;
t2=i+j;
}
}
}
for(j=0;i-j>=0&&i+j<len;j++)
{
if(c[i-j]!=c[i+j+1])
break;
else
{
if(2*j+2>max)
{
max=2*j+2;
t1=i-j;
t2=i+j+1;
}
}
}
}
for(i=b[t1];i<=b[t2];i++)
putchar(a[i]);
printf("\n");
}
return 0;
}
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
char a[5010],c[5010];
int b[5010];
int main()
{
int s;
scanf("%d",&s);getchar();
while(s--)
{
int max,i,j,t1,t2,len;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
gets(a);
len=strlen(a);
j=0;
for(i=0;i<len;i++)
if(isalpha(a[i]))
{
c[j]=tolower(a[i]);
b[j++]=i;
}
len=j;
max=0;
for(i=0;i<len;i++)
{
for(j=0;i-j>=0&&i+j<len;j++)
{
if(c[i-j]!=c[i+j])
break;
else
{
if(2*j+1>max)
{
max=2*j+1;
t1=i-j;
t2=i+j;
}
}
}
for(j=0;i-j>=0&&i+j<len;j++)
{
if(c[i-j]!=c[i+j+1])
break;
else
{
if(2*j+2>max)
{
max=2*j+2;
t1=i-j;
t2=i+j+1;
}
}
}
}
for(i=b[t1];i<=b[t2];i++)
putchar(a[i]);
printf("\n");
}
return 0;
}