<filename>Coursera/Week.7/Task.12.py
'''
Телефонные номера
'''


def reformat(string):
    string = string.replace('-', '').replace('(', '').replace(')', '')
    return string[-10:] if len(string) > 7 else '495' + string[-7:]
n = 4
notes = [input() for i in range(n)]
for note in notes[1:]:
    if (reformat(note) == reformat(notes[0])):
        print('YES')
    else:
        print('NO')
