import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  }
} import java.util.*; util.* java public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  }
} Main public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  } main {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] a = sc.nextLine().toCharArray(); a sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc char[] b = sc.nextLine().toCharArray(); b sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc char[] c = sc.nextLine().toCharArray(); c sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc char k = 'a'; k 'a' int an = 0; an 0 int bn = 0; bn 0 int cn = 0; cn 0 int n = a.length + b.length + c.length; n a.length + b.length + c.length a.length + b.length + c.length a.length a a.length b.length b b.length c.length c c.length String w = ""; w "" System.out.println(w) System.out.println System.out System System.out w String[] args args public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  }
} public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  }
} Main
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    char[] c = sc.nextLine().toCharArray();

    char k = 'a';

    int an = 0;
    int bn = 0;
    int cn = 0;
    int n = a.length + b.length + c.length;

    String w = "";
    LABEL: for (int i = 0; i < n; i++) {
      if (k == 'a') {
        if (an == a.length) {
          w = "A";
          break LABEL;
        } else {
          k = a[an];
          an++;
        }
      } else if (k == 'b') {
        if (bn == b.length) {
          w = "B";
          break LABEL;
        } else {
          k = b[bn];
          bn++;
        }
      } else if (k == 'c') {
        if (cn == c.length) {
          w = "C";
          break LABEL;
        } else {
          k = c[cn];
          cn++;
        }
      }
    }
    
    System.out.println(w);
  }
}