L = list(input().split())

for i in range(len(L)-1):

    if L[i][-1]  != L[i+1][0]:

        print("NO")

        break

else:

  print("YES")

a,b,c = input().split()

if a[-1] == b[0] and b[-1] == c[0]:

  print("YES")

else:

  print("NO")

L = list(input().split())
for i in range(len(L) - 1):
    if L[i][-1] != L[i + 1][0]:
        print("NO")
        break
else:
    print("YES")

a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

-L = list(input().split()) -for i in range(len(L) - 1): -    if L[i][-1] != L[i + 1][0]: -        print("NO") -        break +a, b, c = input().split() +if a[-1] == b[0] and b[-1] == c[0]: +    print("YES") -    print("YES") +    print("NO")