s = input().split()

a, b, c = s[0], s[1], s[2]

if b.startswith(a[-1:]) and c.startswith(b[-1:]):

  print("YES")

else:

  print("NO")
a, b, c = input().split()

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

  print("YES")

else:

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

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

-s = input().split() -a, b, c = s[0], s[1], s[2] -if b.startswith(a[-1:]) and c.startswith(b[-1:]): +a, b, c = input().split() +if a[-1:] == b[:1] and b[-1:] == c[:1]: