Help me in solving PMD7 problem

My issue

n=int(input())
for i in range(n):
x,g=map(int,input().split())
x=str(x)
y=‘’
f=0
for i in x:
if(pow(int(i),g,10)<10):
y+=str(pow(int(i),g,10))
if(y==y[::-1]and int(y)%7==0):
print(“YES”)
else:
print(“NO”)

This is a corrected code, Except it’s showing RTE

My code

n=int(input())
for i in range(n):
    x,g=map(int,input().split())
    x=str(x)
    y=''
    f=0
    for i in x:
        if(pow(int(i),g,10)<10):
            y+=str(pow(int(i),g,10))
    if(y==y[::-1]and int(y)%7==0):
        print("YES")
    else:
        print("NO")
         
        

Problem Link: CodeChef: Practical coding for everyone

@mh2003
Please refer this solution to recheck.

# cook your dish here
for i in range(int(input())):
    n,x=input().split()
    x=int(x)
    a=''
    for i in n:
        f=int(i)**x
        f=f%10
        a+=str(f)
    if (int(a[::-1]))%7==0:
        print('YES')
    else:
        print('NO')