import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    }
} Main public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    } main {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    } try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        } {
            solve(sc);
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) solve(sc) solve sc String[] args args public static void solve(Scanner sc) {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    } solve {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    } char[] aHand = sc.nextLine().toCharArray(); aHand sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc char[] bHand = sc.nextLine().toCharArray(); bHand sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc char[] cHand = sc.nextLine().toCharArray(); cHand sc.nextLine().toCharArray() sc.nextLine().toCharArray sc.nextLine() sc.nextLine sc int a = 0; a 0 int b = 0; b 0 int c = 0; c 0 int next = aHand[a]; next aHand[a] aHand a a++ a while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        } true {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        } switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            } next case 'a': 'a' case 'a': if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                } aHand.length <= a aHand.length aHand aHand.length a {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; break; case 'b': 'b' case 'b': if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                } bHand.length <= b bHand.length bHand bHand.length b {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; break; case 'c': 'c' case 'c': if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                } cHand.length <= c cHand.length cHand cHand.length c {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; break; switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            } next case 'a': 'a' case 'a': next = aHand[a] next aHand[a] aHand a a++ a break; case 'b': 'b' case 'b': next = bHand[b] next bHand[b] bHand b b++ b break; case 'c': 'c' case 'c': next = cHand[c] next cHand[c] cHand c c++ c break; Scanner sc sc public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    }
} Main
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        char[] aHand = sc.nextLine().toCharArray();
        char[] bHand = sc.nextLine().toCharArray();
        char[] cHand = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;

        int next = aHand[a];
        a++;

        while (true) {
            switch (next) {
            case 'a':
                if (aHand.length <= a) {
                    System.out.println("A");
                    return;
                }
                break;
            case 'b':
                if (bHand.length <= b) {
                    System.out.println("B");
                    return;
                }
                break;
            case 'c':
                if (cHand.length <= c) {
                    System.out.println("C");
                    return;
                }
                break;
            }

            switch (next) {
            case 'a':
                next = aHand[a];
                a++;
                break;
            case 'b':
                next = bHand[b];
                b++;
                break;
            case 'c':
                next = cHand[c];
                c++;
                break;
            }
        }
    }
}