Help me in solving SMOL problem

My issue

def sub(n,k):
if(n-k>=0):
return sub(n-k,k)
return n

for i in range(int(input())):
n,k=map(int,input().split())
a=sub(n,k)
print(a)

My code

def sub(n,k):
    if(n-k>=0):
        return sub(n-k,k)
    return n    

for i in range(int(input())):
    n,k=map(int,input().split())
    a=sub(n,k)
    print(a)

Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone

@moulichippada
plzz refer the following solution for better understanding of the logic.

# cook your dish here
t=int(input())
for i in range (t):
    n,k=map(int,input().split())
    if n>=k and k!=0:
        print(n%k)
    else:
        print(n)