Help me in solving LOOP problem

My issue

help me with the problem

My code


t=int(input())

for i in range(t):
    a,b,c=map(int,input().split())
    if b>a:
        d=b-a
        if c>=b:
            e=(c-b)+a
            print(min(d,e))
        else:
            f=c-b
            print(min(d,f))

    elif a>b:
        d=a-b
        if c>=b:
            e=(c-b)+a
            print(min(d,e))
        else:
            f=c-b
            print(min(d,f))
            
        

    
    
    

Problem Link: Circular Track Practice Coding Problem - CodeChef

Better than this solution we can apply recursion where we can reduce the time complexity