• + 9 comments

    My solution:

    for _ in range(int(input())):
        line = input()
        
        while ' && ' in line or ' || ' in line:
            line = line.replace(" && ", " and ").replace(" || ", " or ")
        
        print(line)
    

    No need to complicate things.