#include <iostream>
#include <map>
#include <cctype>
using namespace std;

char getResult(map<char, string> &s){
  char turn, next;
  for(turn = 'a'; s[turn].size() > 0; turn = next){
    next = s[turn][0];
    s[turn] = s[turn].erase(0,1);
  }
  return toupper(turn);
}

int main(){
  map<char, string> s;
  for(char c = 'a'; c <= 'c'; c++){
    cin >> s[c];
  }

  char result = getResult(s);
  cout << result << endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string a, b, c;
    cin >> a >> b >> c;
    if(a.back() == b.front()){
        if(b.back() == c.front()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}