TLE Error for Parting Nums

Problem:

n=int(input())
for i in range(n):
    a,k=map(str,input().split())
    a=int(a)
    r=str(input())
    count=0
    i=len(k)
    K=int(k)
    if a<2*i:
        print(0)
        continue
    if a==2*i:
        p=int(r[:i])
        q=int(r[i:])
        if p%(int(k))==0 and q%(int(k))==0:
            print(1)
        continue
    if a>2*i:
        t=i
        while (a-t)>=i:
            p=int(r[:t])
            q=int(r[t:])
            if p%K==0 and q%K==0:
                count+=1
            t+=1
    print(count)

How to modify the logic to get AC?