import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    }
} Main static Scanner in = new Scanner(System.in); in new Scanner(System.in) public static void main(String[] args) {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    } main {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    } char[] ac = in.nextLine().toCharArray() ac in.nextLine().toCharArray() in.nextLine().toCharArray in.nextLine() in.nextLine in bc = in.nextLine().toCharArray() bc in.nextLine().toCharArray() in.nextLine().toCharArray in.nextLine() in.nextLine in cc = in.nextLine().toCharArray(); cc in.nextLine().toCharArray() in.nextLine().toCharArray in.nextLine() in.nextLine in int a = 0 a 0 b = 0 b 0 c = 0; c 0 char w = 'a'; w 'a' while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        } true {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        } switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            } w case 'a': 'a' case 'a': if (a == ac.length) {
                    System.out.println("A");
                    return;
                } a == ac.length a ac.length ac ac.length {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; w = ac[a++] w ac[a++] ac a++ a break; case 'b': 'b' case 'b': if (b == bc.length) {
                    System.out.println("B");
                    return;
                } b == bc.length b bc.length bc bc.length {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; w = bc[b++] w bc[b++] bc b++ b break; case 'c': 'c' case 'c': if (c == cc.length) {
                    System.out.println("C");
                    return;
                } c == cc.length c cc.length cc cc.length {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; w = cc[c++] w cc[c++] cc c++ c break; String[] args args public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    }
} public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        char[] ac = in.nextLine().toCharArray(), bc = in.nextLine().toCharArray(), cc = in.nextLine().toCharArray();
        int a = 0, b = 0, c = 0;
        char w = 'a';

        while (true) {
            switch (w) {
            case 'a':
                if (a == ac.length) {
                    System.out.println("A");
                    return;
                }
                w = ac[a++];
                break;
            case 'b':
                if (b == bc.length) {
                    System.out.println("B");
                    return;
                }
                w = bc[b++];
                break;
            case 'c':
                if (c == cc.length) {
                    System.out.println("C");
                    return;
                }
                w = cc[c++];
                break;
            }
        }
    }
}
