#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define L 1000001
using namespace std;
char a[L];
int main()
{
int t,i,j,x;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
x=strlen(a);
int mid,flag=0,nine=1;
for(i=0;i<x;i++)
{
if(a[i]!='9')
{
nine=0;
break;
}
}
if(strlen(a)%2!=0)
i=x/2-1,j=x/2+1,mid=x/2;
else
i=x/2-1,j=i+1,mid=i;
while(i>=0)
{
if(a[i]>a[j])
{
flag=1;
break;
}
i--;
j++;
}
if(!flag)
{
//cout<<"old: a[mid]="<<a[mid]<<endl;
if(a[mid]!='9')
a[mid]=(char)((int)a[mid]+1);
else
{
while(a[mid]=='9')
{
a[mid--]='0';
}
a[mid]=(char)((int)a[mid]+1);
}
}
if(nine)
{
printf("1");
if(x%2!=0 && x>1)
{
printf("%.*s", strlen(a)/2+1,a);
reverse(&a[0], &a[x]);
printf("%.*s", strlen(a)-(strlen(a)/2+1),a+strlen(a)/2+2);
}
else
{
printf("%.*s", strlen(a)/2,a);
reverse(&a[0], &a[x]);
printf("%.*s", strlen(a)-(strlen(a)/2),a+strlen(a)/2+1);
}
printf("1\n");
continue;
}
if(x%2!=0)
{
printf("%.*s", strlen(a)/2+1,a);
reverse(&a[0], &a[x]);
printf("%.*s\n", strlen(a)-(strlen(a)/2+1),a+strlen(a)/2+1);
}
else
{
if(a[x/2-1]<a[x/2] && flag==1)
a[x/2-1]=(char)((int)a[x/2-1]+1);
printf("%.*s", strlen(a)/2,a);
reverse(&a[0], &a[x]);
printf("%.*s\n", strlen(a)-(strlen(a)/2),a+strlen(a)/2);
}
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPGlvc3RyZWFtPgojaW5jbHVkZTxhbGdvcml0aG0+CiNkZWZpbmUgTCAxMDAwMDAxCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiBjaGFyIGFbTF07CmludCBtYWluKCkKewogCiAgICBpbnQgdCxpLGoseDsKICAgIHNjYW5mKCIlZCIsJnQpOwogICAgd2hpbGUodC0tKQogICAgewogICAgICAgIHNjYW5mKCIlcyIsYSk7CiAgICAgICB4PXN0cmxlbihhKTsKICAgICAgICBpbnQgbWlkLGZsYWc9MCxuaW5lPTE7CiAgICAgICAgZm9yKGk9MDtpPHg7aSsrKQogICAgICAgICAgIHsKICAgICAgICAgICAgaWYoYVtpXSE9JzknKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBuaW5lPTA7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgIH0KICAgICAgICBpZihzdHJsZW4oYSklMiE9MCkKICAgICAgICAgICAgaT14LzItMSxqPXgvMisxLG1pZD14LzI7CiAgICAgICAgZWxzZQogICAgICAgICAgICBpPXgvMi0xLGo9aSsxLG1pZD1pOwogICAgICAgIHdoaWxlKGk+PTApCiAgICAgICAgewogICAgICAgICAgICBpZihhW2ldPmFbal0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgIGZsYWc9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaS0tOwogICAgICAgICAgICBqKys7CiAgICAgICAgfQogICAgICAgIGlmKCFmbGFnKQogICAgICAgIHsKICAgICAgICAgICAgLy9jb3V0PDwib2xkOiBhW21pZF09Ijw8YVttaWRdPDxlbmRsOwogICAgICAgICAgICBpZihhW21pZF0hPSc5JykKICAgICAgICAgICAgICAgIGFbbWlkXT0oY2hhcikoKGludClhW21pZF0rMSk7CiAKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB3aGlsZShhW21pZF09PSc5JykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBhW21pZC0tXT0nMCc7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBhW21pZF09KGNoYXIpKChpbnQpYVttaWRdKzEpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmKG5pbmUpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIjEiKTsKICAgICAgICAgaWYoeCUyIT0wICYmIHg+MSkKICAgICAgIHsKICAgICAgICBwcmludGYoIiUuKnMiLCBzdHJsZW4oYSkvMisxLGEpOwogICAgICAgIHJldmVyc2UoJmFbMF0sICZhW3hdKTsKICAgICAgICBwcmludGYoIiUuKnMiLCBzdHJsZW4oYSktKHN0cmxlbihhKS8yKzEpLGErc3RybGVuKGEpLzIrMik7CiAgICAgICB9CiAgICAgICBlbHNlCiAgICAgICB7CiAgICAgICAgcHJpbnRmKCIlLipzIiwgc3RybGVuKGEpLzIsYSk7CiAgICAgICAgcmV2ZXJzZSgmYVswXSwgJmFbeF0pOwogICAgICAgIHByaW50ZigiJS4qcyIsIHN0cmxlbihhKS0oc3RybGVuKGEpLzIpLGErc3RybGVuKGEpLzIrMSk7CiAgICAgICB9CiAgICAgICBwcmludGYoIjFcbiIpOwogICAgICAgY29udGludWU7CiAgICAgICAgfQogCiAKICAgICAgICBpZih4JTIhPTApCiAgICAgICB7CiAgICAgICAgcHJpbnRmKCIlLipzIiwgc3RybGVuKGEpLzIrMSxhKTsKICAgICAgICByZXZlcnNlKCZhWzBdLCAmYVt4XSk7CiAgICAgICAgcHJpbnRmKCIlLipzXG4iLCBzdHJsZW4oYSktKHN0cmxlbihhKS8yKzEpLGErc3RybGVuKGEpLzIrMSk7CiAgICAgICB9CiAgICAgICBlbHNlCiAgICAgICB7CiAgICAgICAgICBpZihhW3gvMi0xXTxhW3gvMl0gJiYgZmxhZz09MSkKICAgICAgICAgICAgICAgIGFbeC8yLTFdPShjaGFyKSgoaW50KWFbeC8yLTFdKzEpOwogICAgICAgIHByaW50ZigiJS4qcyIsIHN0cmxlbihhKS8yLGEpOwogICAgICAgIHJldmVyc2UoJmFbMF0sICZhW3hdKTsKICAgICAgICBwcmludGYoIiUuKnNcbiIsIHN0cmxlbihhKS0oc3RybGVuKGEpLzIpLGErc3RybGVuKGEpLzIpOwogICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=