Palin- next palindrome

#include<bits/stdc++.h>
//#define _OPEN_SYS_ITOA_EXT
//#include <stdio.h>
//#include <stdlib.h>
using namespace std;
bool palin(int num )
{
string s ;
s = to_string(num) ;
int l = 0;
int r = s.length() - 1;
while(l < r)
{
if(s[l] != s[r])
return false ;
l++ ;
r–;
}
return true ;
}
int main() {

// your code here

int t ; 
cin >> t ; 
while(t--)
{
	 string s ; 
	cin >> s; 
 	//string s = to_string(num) ; 
 	int l = 0; 
 	int r = s.length() -1; 
 	while( l <= r)
 	{
 		if(s[l] == s[r] && s[r] == '9')
 		{
 			l++; 
 			r--; 
 		}
 		else 
 		break;
 	}
 	if(l > r)
 	{
 		string ans1 ;
 		char one = '1' ; 
 		ans1.push_back(one) ; 
 		char zero = '0' ;
 		for(int i = 0; i < s.length() -1;i++)
 		ans1.push_back(zero) ; 
 		ans1.push_back(one) ; 
 		
 		cout << ans1 ; 
 		if(t > 0)
 		cout << endl ;
 		continue ; 
 		
 	}
 	string ans = s ;
 	l = 0; 
 	r = s.length() - 1; 
 //	cout << ans << endl ;
 	while(l < r)
 	{
 		ans[r] = s[l] ; 
 		r--; 
 		l++ ; 
 	}
 	//cout << ans << endl ; 
 	  int n = s.length() ; 
 	if(ans <= s)
 	{
 	  
 	    if(n%2 != 0 )
 	    {
 	      int h = n/2 ; 
 	      if(ans[h] != '9')
 	      {
 	          int k = ans[h] - '0' ; 
 	          k++ ; 
 	          ans[h] = k + '0' ; 
 	      }
 	      else 
 	      ans[h] = '0' ; 
 	    }
 	    l = n/2 - 1; 
 	    if(n%2 == 0 )
 	    r = n/2 ; 
 	    else 
 	    r = n/2 + 1; 
 	    while( l != 0 &&  ans <= s)
 	    {
 	        if(ans[l] != '9')
 	        {
 	            int k = ans[l] - '0' ; 
 	            k++ ; 
 	          ans[r] = ans[l] = k + '0' ; 
 	        }
 	        else 
 	        ans[r] = ans[l] = '0' ; 
 	        l--; 
 	        r++ ; 
 	        
 	    }
 	}
 	 
 	 cout << ans; 
 	 if(t > 0 ) 
 	 cout << endl ; 
 	
 	
	
	 
}
return 0;

}

showing time limit exceeded, what am I doing wrong ?

A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.

Input:
2
808
2133
Output:
818
2222

First format your code using ``` symbol at start and end of code