import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  }

} import java.util.*; util.* java public class Main {

  public static void main (String[] args) {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  }

} Main public static void main (String[] args) {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  } main {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String sa = scanner.next(); sa scanner.next() scanner.next scanner String sb = scanner.next(); sb scanner.next() scanner.next scanner String sc = scanner.next(); sc scanner.next() scanner.next scanner scanner.close() scanner.close scanner String[] SA = sa.split(""); SA sa.split("") sa.split sa "" String[] SB = sb.split(""); SB sb.split("") sb.split sb "" String[] SC = sc.split(""); SC sc.split("") sc.split sc "" int currentSA = 0; currentSA 0 int currentSB = 0; currentSB 0 int currentSC = 0; currentSC 0 String turn = "a"; turn "a" String winner = ""; winner "" while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    } winner.equals("") winner.equals winner "" {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    } if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      } turn.equals("a") turn.equals turn "a" {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        } currentSA == SA.length currentSA SA.length SA SA.length {
          winner = "A";
        } winner = "A" winner "A" {
          turn = SA[currentSA];
          currentSA++;
        } turn = SA[currentSA] turn SA[currentSA] SA currentSA currentSA++ currentSA if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      } turn.equals("b") turn.equals turn "b" {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        } currentSB == SB.length currentSB SB.length SB SB.length {
          winner = "B";
        } winner = "B" winner "B" {
          turn = SB[currentSB];
          currentSB++;
        } turn = SB[currentSB] turn SB[currentSB] SB currentSB currentSB++ currentSB {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      } if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        } currentSC == SC.length currentSC SC.length SC SC.length {
          winner = "C";
        } winner = "C" winner "C" {
          turn = SC[currentSC];
          currentSC++;
        } turn = SC[currentSC] turn SC[currentSC] SC currentSC currentSC++ currentSC System.out.println(winner) System.out.println System.out System System.out winner String[] args args public class Main {

  public static void main (String[] args) {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  }

} public class Main {

  public static void main (String[] args) {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  }

} Main
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner scanner = new Scanner(System.in);

    String sa = scanner.next();
    String sb = scanner.next();
    String sc = scanner.next();

    scanner.close();

    String[] SA = sa.split("");
    String[] SB = sb.split("");
    String[] SC = sc.split("");

    int currentSA = 0;
    int currentSB = 0;
    int currentSC = 0;

    // a:Aの番、b:Bの番、c:Cの番
    String turn = "a";

    String winner = "";

    while (winner.equals("")) {
      if (turn.equals("a")) {
        if (currentSA == SA.length){
          winner = "A";
        } else {
          turn = SA[currentSA];
          currentSA++;
        }
      } else if(turn.equals("b")) {
        if (currentSB == SB.length){
          winner = "B";
        } else {
          turn = SB[currentSB];
          currentSB++;
        }
      } else {
        if (currentSC == SC.length){
          winner = "C";
        } else {
          turn = SC[currentSC];
          currentSC++;
        }
      }
    }

    System.out.println(winner);

  }

}