Help me in solving CHANGEXY problem

My issue

I don’t think there is any error; what test case may it fail? Can anyone tell me?
I built the program thinking of the test case 3 41 2 and it is best achieved as: 3 + 1 = 4
42 = 8
8+1 = 9
9
2 = 18
18+1 = 19
19*2 = 38
38 + 3 = 41

My code

T = int(input())
for i in range (T):
    A,B,K = list(map(int,input().split()))
    cnt = 0
    while B>A:
        if B%K != 0:
            # print ('1')
            cnt += B%K
            B = B- B%K
            if B==A:
                break
        elif B>= A*K:
            # print ('2')
            B = B//K
            cnt += 1
        else:
            # print ('3')
            cnt += B-A
            B = A
            
        # print (B)
    print (cnt)

Problem Link: Change A to B Practice Coding Problem