import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    } main {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next().toUpperCase(); a sc.next().toUpperCase() sc.next().toUpperCase sc.next() sc.next sc String b = sc.next().toUpperCase(); b sc.next().toUpperCase() sc.next().toUpperCase sc.next() sc.next sc String c = sc.next().toUpperCase(); c sc.next().toUpperCase() sc.next().toUpperCase sc.next() sc.next sc int idxa = 0; idxa 0 int idxb = 0; idxb 0 int idxc = 0; idxc 0 char temp = 'A'; temp 'A' while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        } true {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        } if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            } temp == 'A' temp 'A' {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } if (idxa >= a.length()) {
                    break;
                } idxa >= a.length() idxa a.length() a.length a {
                    break;
                } break; temp = a.charAt(idxa) temp a.charAt(idxa) a.charAt a idxa idxa++ idxa if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            } temp == 'B' temp 'B' {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } if (idxb >= b.length()) {
                    break;
                } idxb >= b.length() idxb b.length() b.length b {
                    break;
                } break; temp = b.charAt(idxb) temp b.charAt(idxb) b.charAt b idxb idxb++ idxb if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            } temp == 'C' temp 'C' {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            } if (idxc >= c.length()) {
                    break;
                } idxc >= c.length() idxc c.length() c.length c {
                    break;
                } break; temp = c.charAt(idxc) temp c.charAt(idxc) c.charAt c idxc idxc++ idxc System.out.println(temp) System.out.println System.out System System.out temp String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    }
}