• + 0 comments

    readable version:

    import re
    
    regex = re.compile(r'^[Hh][Ii] [^Dd]')
    
    n = int(input())
    for _ in range(n):
        line = input()
        if (regex.match(line)):
            print(line)