import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
  auto S = [readln.chomp, readln.chomp, readln.chomp];

  auto current = 0;
  int[3] count;
  while (true) {
    if (count[current] == S[current].length) {
      writeln(current == 0 ? "A" : current == 1 ? "B" : "C");
      return;
    }
   auto next = S[current][count[current]] - 'a';
   count[current]++;
   current = next;
  }
}
