#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define CASES int t;cin>>t;while(t--)
#define REP(i, val, b) for (int i = val; i < b; ++i)
class stringMod
{
public:
string s;
//Here is the increment frunction.
void increment(int pos)
{
s[pos]++; //We have incremented right most digit by "1"
/*
When the right most digit is "9" and you are trying to increment it by "1", then that
will become ":" in cpp. So we have checked ":" in condition here.
*/
if (s[pos] == ':')
{
//First we will make that position to "0".
//Here is the explanation with example. if the number is 139 and we will do s[2]++.
//Then first it will become "13:". So in this line we will make ":" to "0".
//So our number will become "130".
//Now our task is to increment "3" to "4". So we will do increment(pos - 1) here if and only
//if pos > 0. Now you must have question in your mind that what is the meaning of the
//condition if (pos > 0). So here is the explanation. If our number is 139, then our position
//is 2 and we are incrementing our position by 1 so it will become "13:" and after that "130"
//and position is 2 so here position is 2 that is greater than 0 so we will increment
//previous position. So we will increment position 2, so our number will become 140.
//Now we are moving towards to else part. When will these condition happen.
//So if we have a number "99" and we have reached to this part and our number
//have became "9:" and then "90". Now here our position is 1 as we have incremented
//last digit so we will increment 0th position, then
//our number will become ":0" and after that our number will become "00" and after that our
//position is 0 so we have to prepend "1" to our number so our numbber will become "100".
//and this process will run again. So this is the else part explanation.
s[pos] = '0';
if (pos > 0)
{
increment(pos - 1);
}
else
{
s.insert(s.begin(), '1');
}
}
}
};
int main()
{
CASES{
stringMod s;
cin >> s.s;
int l = s.s.length(); //length of the input || number
//First we will increment last digit by "1",
//so that we will check whether the next number is palindrome or not
s.increment(l - 1);
l = s.s.length();
//As I have explained we will loop through half of the length of input.
REP(i, 0, l / 2)
{
int left = i; //left most digit is this from the input || number
int right = (l - 1) - i; //right most digit is thie from input || number
//Will run while loop until left and right number is equal as explained
while (s.s[left] != s.s[right])
{
//If not equal we will increment right most number by "1".
s.increment(right);
}
}
//Here is the final string.
cout << s.s << endl;
}
return 0;
}