'use strict'

function main(s) {
  s = s.split('\n');

  const a = s[0].split('');
  const b = s[1].split('');
  const c = s[2].split('');

  const game = (turn) => {
    if (turn === 'a') return game(a.shift()) || 'A';
    if (turn === 'b') return game(b.shift()) || 'B';
    if (turn === 'c') return game(c.shift()) || 'C';
  }

  const winner = game('a');
  console.log(winner);
}

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