import java.util.*;

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();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    }
} import java.util.*; util.* java 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();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    }
} 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();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc char x = a.charAt(0); x a.charAt(0) a.charAt a 0 int cnta = 1; cnta 1 int cntb = 0; cntb 0 int cntc = 0; cntc 0 while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        } true {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        } if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            } x == 'a' x 'a' {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                } Exception e {
                    System.out.println("A");
                    System.exit(0);
                } System.out.println("A") System.out.println System.out System System.out "A" System.exit(0) System.exit System 0 {
                    x = a.charAt(cnta);
                } x = a.charAt(cnta) x a.charAt(cnta) a.charAt a cnta cnta++ cnta if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            } x == 'b' x 'b' {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                } Exception e {
                    System.out.println("B");
                    System.exit(0);
                } System.out.println("B") System.out.println System.out System System.out "B" System.exit(0) System.exit System 0 {
                    x = b.charAt(cntb);
                } x = b.charAt(cntb) x b.charAt(cntb) b.charAt b cntb cntb++ cntb {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            } try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                } Exception e {
                    System.out.println("C");
                    System.exit(0);
                } System.out.println("C") System.out.println System.out System System.out "C" System.exit(0) System.exit System 0 {
                    x = c.charAt(cntc);
                } x = c.charAt(cntc) x c.charAt(cntc) c.charAt c cntc cntc++ cntc String[] args args 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();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    }
} 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();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    }
} Main
import java.util.*;

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();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    }
}
