import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String SA = sc.next(); SA sc.next() sc.next sc String SB = sc.next(); SB sc.next() sc.next sc String SC = sc.next(); SC sc.next() sc.next sc int ia = 0; ia 0 int ib = 0; ib 0 int ic = 0; ic 0 char next = 'a'; next 'a' String ans = ""; ans "" while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    } true {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    } if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      } next == 'a' next 'a' {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } if (ia == SA.length()) {
          ans = "A";
          break;
        } ia == SA.length() ia SA.length() SA.length SA {
          ans = "A";
          break;
        } ans = "A" ans "A" break; next = SA.charAt(ia) next SA.charAt(ia) SA.charAt SA ia ia++ ia if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      } next == 'b' next 'b' {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } if (ib == SB.length()) {
          ans = "B";
          break;
        } ib == SB.length() ib SB.length() SB.length SB {
          ans = "B";
          break;
        } ans = "B" ans "B" break; next = SB.charAt(ib) next SB.charAt(ib) SB.charAt SB ib ib++ ib { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      } if (ic == SC.length()) {
          ans = "C";
          break;
        } ic == SC.length() ic SC.length() SC.length SC {
          ans = "C";
          break;
        } ans = "C" ans "C" break; next = SC.charAt(ic) next SC.charAt(ic) SC.charAt SC ic ic++ ic System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    int ia = 0;
    int ib = 0;
    int ic = 0;
    char next = 'a';
    String ans = "";
    while (true) {
      if (next == 'a') {
        if (ia == SA.length()) {
          ans = "A";
          break;
        }
        next = SA.charAt(ia);
        ia++;
      } else if (next == 'b') {
        if (ib == SB.length()) {
          ans = "B";
          break;
        }
        next = SB.charAt(ib);
        ib++;
      } else { // c
        if (ic == SC.length()) {
          ans = "C";
          break;
        }
        next = SC.charAt(ic);
        ic++;
      }
    }
    
    System.out.println(ans);
  }
}