Help me in solving CRDGAME problem

My issue

My code

# cook your dish here
for _ in range(int(input())):
    n=int(input())
    c,m,d=0,0,0
    for i in range(n):
        a,b=map(int,input().split())
        s=0
        if a>b:
            while(a!=0):
                r=a%10
                s=s+r
                a=a/10
            if s<b:
                m+=1
            elif s>b:
                c+=1
            else:
                d+=1 
        else:
            while(b!=0):
                r=b%10
                s+=r 
                b=b/10
            if s<a:
                c+=1 
            elif s>a:
                m+=1 
            else:
                d+=1
    if c!=m:
        if c>m:
            print(0,c)
        else:
            print(1,m)
    else:
        print(2,c)

Problem Link: CRDGAME Problem - CodeChef