#include<stdio.h>
int main()
{
	char a[11],b[11],c[11];
	int i=0,j=0,y=0,x=0;
	scanf("%s",a);
	getchar();
	scanf("%s",b);
	getchar();
	scanf("%s",c);
	while(a[i]!='\0')
		i++;
	while(b[j]!='\0')
		j++;
    if(a[i-1]==b[0])
		x=1;
	if(b[j-1]==c[0])
		y=1;
	if(x==1&&y==1)
		printf("YES\nThey form a word chain.");
	else if(x==1&&y==0)
		printf("NO\nA and B form a word chain, but B and C do not.");
	else if(x==0&&y==1)
		printf("NO\nB and C form a word chain, but A and B do not.");
	else
		printf("No");
	return 0;
}
