'use strict';

const lines = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

let aCards = lines[0].split("");
let bCards = lines[1].split("");
let cCards = lines[2].split("");

function moveAnotherMan(someoneCards) {
  if (someoneCards.length === 0) {
    anyoneWin(someoneCards);
    return;
  }
  switch (someoneCards[0]) {
    case "a":
      someoneCards.shift();
      moveAnotherMan(aCards);
    break;
    case "b":
      someoneCards.shift();
      moveAnotherMan(bCards);
    break;
    case "c":
      someoneCards.shift();
      moveAnotherMan(cCards);
    break;
  }
};

function anyoneWin(who) {
  if (who===aCards) {
    console.log("A");
  }
  if (who===bCards) {
    console.log("B");
  }
  if (who===cCards) {
    console.log("C");
  }
}

moveAnotherMan(aCards);