#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc045_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string A, B, C;
  cin >> A >> B >> C;

  int a = 0, b = -1, c = -1;
  char next = 'a';
  while (true) {
    if (next == 'a') {
      a++;
      if (a == A.size()) {
        cout << "A" << endl;
        return 0;
      }
      next = A[a];
    } else if (next == 'b') {
      b++;
      if (b == B.size()) {
        cout << "B" << endl;
        return 0;
      }
      next = B[b];
    } else {
      c++;
      if (c == C.size()) {
        cout << "C" << endl;
        return 0;
      }
      next = C[c];
    }
  }
}
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e18;
set<int> s;
int n,x;
void solve()
 {
  cin>>n;
  loop(i,0,n)
   {
	   cin>>x;
	   s.insert(x);
	}
 cout<<((int)s.size() == n ? "YES" : "NO");
  
 }  
signed main()
 {   
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0); 
   /*int t;
   cin>>t;
   loop(i,1,t+1)*/
      solve();
      
  //cerr<<END<<1.0*clock();
  return 0;
} 
