#Here's my code:
for _ in range(int(input())) :
loco = input()
A,B = map(int , input().split())
locations = []
for i in range(len(loco)) :
if(loco[i] == "A"):
locations.append(i)
elif(loco[i] == "B"):
locations.append(i)
distance = abs(locations[0] - locations[1])
if(distance % (A + B) == 0):
print("unsafe")
else:
print("safe")
It clears the sample testcases and seems correct, but is not giving AC. No error was shown when i tested it on IDE
@galencolin @ssrivastava990 @akshitm16