1#include <iostream>
2
3
4bool isPalindrome (int number) {
5 int decomposed = number, reversed = 0;
6 while (decomposed) {
7 reversed = 10 * reversed + (decomposed % 10);
8 decomposed /= 10;
9 }
10 return reversed == number;
11}
12
13
14int nextPalindromicNumber (int number) {
15 while (!isPalindrome(++number));
16 return number;
17}
18
19
20int main () {
21 int testCases;
22 std::cin >> testCases;
23 while (testCases--) {
24 int number;
25 std::cin >> number;
26 std::cout << nextPalindromicNumber(number) << '\n';
27 }
28}
29
1#include <iostream>
2#include <string.h>
3using namespace std;
4int nextpalin (int num){
5 while (num++) {
6 string str = to_string (num); /// int to string conversion
7 int l = str.length()-1;
8 int s = 0;
9 while( s<l ){
10 if (str[s]!=str[l]) break;
11 else {
12 s++;
13 l--;
14 }
15 if (s>=l) return num;}
16 }
17 }
18
19int main () {
20 int t;
21 cin >> t;
22 while (t--){
23 int num;
24 cin >> num;
25 if (num==0) cout << "1" << endl;
26 else {
27 if (num<9) cout << num+1 << endl;
28 else cout << nextpalin( num) << endl;}
29 }
30}
31