• + 0 comments

    Managed to more or less fit all replacement logic into one line:

    import re
    
    n = int(input())
    for _ in range(n):
        print(re.sub(r"(?<= )\|\|(?= )", "or", re.sub(r"(?<= )&&(?= )", "and", input())))