• + 0 comments

    With the help of comprehension lists -->

    import sys, re
    
    N = sys.stdin.read().splitlines()[1:]
    pattern = r"^[789]\d{9}$"
    
    match = ['YES' if re.search(pattern, line) else 'NO' for line in N]
    
    for _ in match:
        print(_)