#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, m, n;
  int aa, bb, cc;
  char d, f;
  char a[110], b[110], c[110];
  cin >> a >> b >> c;
  aa = strlen(a);
  bb = strlen(b);
  cc = strlen(c);
  i = 1, j = 0, k = 0;
  d = a[0];
  while (1) {
    if (d == 'a') {
      d = a[i];
      i++;
    }
    if (d == 'b') {
      d = b[j];
      j++;
    }
    if (d == 'c') {
      d = c[k];
      k++;
    }
    if (i == aa + 1) {
      cout << 'A' << endl;
      return 0;
    }
    if (i == cc + 1) {
      cout << 'C' << endl;
      return 0;
    }
    if (i == bb + 1) {
      cout << 'B' << endl;
      return 0;
    }
  }
  return 0;
}
