Help me in solving LOOP problem

My issue

Can anyone please tell the failing cases for my algorithm and coding below -

Algo: if the absolute difference between B-A <= M/2 then output is absolute diff of B-A.
else, (M-B) + A be the output.

Explanation: eg. A = 3, B = 75, M = 100.
abs(B-A) = 72 i.e. > M/2 which is 50.
for this as per my algorithm, output is -
M-B + A-0 (for ring or circular path, start point = end point) = 100-75+3=28.

coding:
T = int(input())
for _ in range(T):
A, B, M = map(int, input().split())
if (A!=M):
if abs(B-A) <= M/2:
print(abs(B-A))
else:
print(abs(B-M)+A)
else:
if B >= M/2:
print(abs(B-A))
else:
print(B)

My code

# cook your dish here
T = int(input())
for _ in range(T):
    A, B, M = map(int, input().split())
    if (A!=M):
        if abs(B-A) <= M/2:
            print(abs(B-A))
        else:
            print(abs(B-M)+A)
    else:
        if B >= M/2:
            print(abs(B-A))
        else:
            print(B)

Problem Link: LOOP Problem - CodeChef

@mk1910
The answer will we minimum of abs(A-B) and M-abs(A-B).