import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    StringBuilder aa = new StringBuilder(a);
    StringBuilder bb = new StringBuilder(b);
    StringBuilder cc = new StringBuilder(c);
    char x = aa.charAt(0);
    String ans = "";
    while (true) {
      if (x == 'a') {
        if (aa.length() == 0) {
          ans = "A";
          break;
        } else {
        x = aa.charAt(0);   
        aa.delete(0,1);
        }
      }
      if(x == 'b') {
        if (bb.length() == 0) {
          ans = "B";
          break;
        } else {
        x = bb.charAt(0); 
        bb.delete(0,1);
        }
      }
      if(x == 'c') {
        if (cc.length() == 0) {
          ans = "C";
          break;
        } else {
        x = cc.charAt(0); 
        cc.delete(0,1);
        }
      }
    }

    System.out.println(ans);
    
  }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz