Help me in solving DIGSMPAR problem

My issue

t=int(input())
for i in range(t):
n=input()
c=0
for j in range(len(n)-1,0,-1):
if n[j]==“9”:
c+=1
else:
break
if c%2!=0:
print(int(n)+2)
else:
print(int(n)+1)

My code

# cook your dish here
t=int(input())
for i in range(t):
    n=input()
    c=0
    for j in range(len(n)-1,0,-1):
        if n[j]=="9":
            c+=1
        else:
            break
    if c%2!=0:
        print(int(n)+2)
    else:
        print(int(n)+1)

Problem Link: Digit Sum Parities Practice Coding Problem - CodeChef

@khushisahu0108
your logic is not right .
if it helps plzz refer my c++ code for better understanding of the logic.
ping me in case u get stuck at any point

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int n1=n;
	    int cal=0;
	    while(n1>0)
	    {
	        cal+=(n1%10);
	        n1/=10;
	    }
	    if(cal%2)
	    cal=0;
	    else
	    cal=1;
	    for(int i=n+1; ;i++)
	    {
	        int ch=i;
	        int ans=0;
	        while(ch>0)
	        {
	            ans+=(ch%10);
	            ch/=10;
	        }
	        if(ans%2==cal)
	        {
	            cout<<i<<endl;
	            break;
	        }
	    }
	}
	return 0;
}