function Main(input) {
  input = input.split("\n");
  var a = input[0];
  var b = input[1];
  var c = input[2];

  var aList = [a.split(""), "A"];
  var bList = [b.split(""), "B"];
  var cList = [c.split(""), "C"];

  var turn = aList;

  while (true) {
    if (turn[0].length > 0) {
      var first = turn[0][0];
      turn[0].shift();
      if (first === "a") {
        turn = aList;
      }
      if (first === "b") {
        turn = bList;
      }
      if (first === "c") {
        turn = cList;
      }
    } else if (!(turn[0].length > 0)) {
      console.log(turn[1]);
      break;
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
