#include <iostream>
#include <cstring>
using namespace std;


char S[3][128];
int n[3];
int p = 0;
char ans;

int main(void) {
  cin >> S[0] >> S[1] >> S[2];

  n[0] = n[1] = n[2] = 0;
  while(n[p] < strlen(S[p])) {
    p = S[p][n[p]++] - 'a';
  }

  ans = 'A' + p;
  cout << ans << endl;

  return 0;
}
