#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
using namespace std;
inline void add (string& str, int lo, int hi)
{
int j, carry=1;
for(j=hi; j>=lo && carry; j--)
{
if(str[j]=='9')
{
str[j]='0';
carry=1;
}
else
{
str[j]=str[j]+'1'-'0';
carry=0;
}
}
return;
}
inline bool lesscheck(string str)
{
string rev;
int i, l=str.size()-1;
for(i=(l%2==0)?(l/2-1):(l/2);i>=0;i--)
rev.push_back(str[i]);
if(l%2 == 0 && rev > str.substr(l/2+1, l/2))
return true;
else if(l%2 == 1 && rev > str.substr(l/2+1, l/2+1))
return true;
else return false;
}
inline void recover (string& str)
{
int i, lo=0, hi=str.size()-1;
for(i=lo; i<=hi/2; i++)
str[hi-i]=str[i];
}
inline void endcase(string& str)
{
int l=str.size();
str[0]='1';
str.push_back('1');
if(l%2==0)str[l/2]='0';
return;
}
int main( )
{
int l, i, j,t, carry;
string str;
vector<string> ans;
vector<string>::iterator it;
scanf("%d", &t);
for(i=0; i<t; i++)
{
cin >> str;
l = str.size()-1;
if(!lesscheck(str))
{
add(str, 0, l/2);
if(str[0]=='0')
endcase(str);
recover(str);
}
else
recover(str);
ans.push_back(str);
str.clear();
}
for(it=ans.begin(); it!=ans.end(); it++)
cout << *it << endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0ZGlvLmg+CiNpbmNsdWRlPHN0cmluZy5oPgojaW5jbHVkZTxzdGRsaWIuaD4KI2luY2x1ZGU8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmlubGluZSB2b2lkIGFkZCAoc3RyaW5nJiBzdHIsIGludCBsbywgaW50IGhpKQp7CmludCBqLCBjYXJyeT0xOwogCmZvcihqPWhpOyBqPj1sbyAmJiBjYXJyeTsgai0tKQp7CmlmKHN0cltqXT09JzknKQp7CnN0cltqXT0nMCc7CmNhcnJ5PTE7Cn0KZWxzZQp7CnN0cltqXT1zdHJbal0rJzEnLScwJzsK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