import java.lang.;
import java.util.;
class NextPallindrome
{
int calc(int x)
{
if(x==0)
{
x++;
}
else if(((int)Math.log10(x)+1)==1)
{
if(x!=9)
x++;
else
x=11;
}
else
{ int y;boolean b=true;
int len=(int)Math.log10(x)+1;
String str=Integer.toString(x);
if(len%2==0)
{
char ch=str.charAt(len/2-1);
if((int)ch<=(int)str.charAt(len/2))
{
y=Integer.parseInt(str.substring(0,len/2));
str=Integer.toString(y);
if(str.length()!=Integer.toString(y+1).length())
{
b=false;
}
y++;
}
else
{
y=Integer.parseInt(str.substring(0,len/2));
}
str=Integer.toString(y);
if(b){
for(y=str.length()-1;y>=0;y--)
{
str+=str.charAt(y);
}
}
else
{
for(y=str.length()-2;y>=0;y--)
{
str+=str.charAt(y);
}
}
x=Integer.parseInt(str);
}
else
{
char ch=str.charAt(len/2);
if((int)ch<=(int)str.charAt(len/2+1))
{
y=Integer.parseInt(str.substring(0,len/2+1));
str=Integer.toString(y);
if(str.length()!=Integer.toString(y+1).length())
{
b=false;
}
y++;
}
else
{
y=Integer.parseInt(str.substring(0,len/2+1));
}
str=Integer.toString(y);
if(b){
for(y=str.length()-2;y>=0;y--)
{
str+=str.charAt(y);
}
}
else
{
for(y=str.length()-3;y>=0;y--)
{
str+=str.charAt(y);
}
}
x=Integer.parseInt(str);
}
}
return x;
}
public static void main(String srgs[])throws Exception
{
Scanner sc=new Scanner(System.in);
NextPallindrome obj=new NextPallindrome();
int t;
t=sc.nextInt();
int data[]=new int[t];
for(int i=0;i<t;i++)
{
data[i]=sc.nextInt();
}
for(int i=0;i<t;i++)
{
data[i]=obj.calc(data[i]);
}
for(int i=0;i<t;i++)
{
System.out.println(data[i]);
}
}
}