import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.File;
import java.util.*;

public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    }

}

class Solver {
    public void solve(String a, String b, String c) {
        String ans = "";
        char turn = 'a';
        int an = a.length();
        int bn = b.length();
        int cn = c.length();
        while (true) {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        }
        Main.output.append(ans);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.FileWriter; FileWriter java.io import java.io.PrintWriter; PrintWriter java.io import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset import java.io.BufferedWriter; BufferedWriter java.io import java.io.FileReader; FileReader java.io import java.io.File; File java.io import java.util.*; util.* java public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    }

} Main public static StringBuilder output = new StringBuilder(); output new StringBuilder() public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    } main {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) String a = in.next().trim(); a in.next().trim() in.next().trim in.next() in.next in String b = in.next().trim(); b in.next().trim() in.next().trim in.next() in.next in String c = in.next().trim(); c in.next().trim() in.next().trim in.next() in.next in Solver solver = new Solver(); solver new Solver() solver.solve(a, b, c) solver.solve solver a b c System.out.println(output) System.out.println System.out System System.out output String[] args args class Solver {
    public void solve(String a, String b, String c) {
        String ans = "";
        char turn = 'a';
        int an = a.length();
        int bn = b.length();
        int cn = c.length();
        while (true) {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        }
        Main.output.append(ans);
    }
} Solver public void solve(String a, String b, String c) {
        String ans = "";
        char turn = 'a';
        int an = a.length();
        int bn = b.length();
        int cn = c.length();
        while (true) {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        }
        Main.output.append(ans);
    } solve {
        String ans = "";
        char turn = 'a';
        int an = a.length();
        int bn = b.length();
        int cn = c.length();
        while (true) {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        }
        Main.output.append(ans);
    } String ans = ""; ans "" char turn = 'a'; turn 'a' int an = a.length(); an a.length() a.length a int bn = b.length(); bn b.length() b.length b int cn = c.length(); cn c.length() c.length c while (true) {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        } true {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        } if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            } turn == 'a' turn 'a' {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            } if (an == 0) {
                    ans = "A";
                    break;
                } an == 0 an 0 {
                    ans = "A";
                    break;
                } ans = "A" ans "A" break; turn = a.charAt(a.length() - an) turn a.charAt(a.length() - an) a.charAt a a.length() - an a.length() a.length a an an-- an if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            } turn == 'b' turn 'b' {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            } if (bn == 0) {
                    ans = "B";
                    break;
                } bn == 0 bn 0 {
                    ans = "B";
                    break;
                } ans = "B" ans "B" break; turn = b.charAt(b.length() - bn) turn b.charAt(b.length() - bn) b.charAt b b.length() - bn b.length() b.length b bn bn-- bn if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            } turn == 'c' turn 'c' {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            } if (cn == 0) {
                    ans = "C";
                    break;
                } cn == 0 cn 0 {
                    ans = "C";
                    break;
                } ans = "C" ans "C" break; turn = c.charAt(c.length() - cn) turn c.charAt(c.length() - cn) c.charAt c c.length() - cn c.length() c.length c cn cn-- cn Main.output.append(ans) Main.output.append Main.output Main Main.output ans String a a String b b String c c public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    }

} public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.File;
import java.util.*;

public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next().trim();
        String b = in.next().trim();
        String c = in.next().trim();
        Solver solver = new Solver();
        solver.solve(a, b, c);
        System.out.println(output);
    }

}

class Solver {
    public void solve(String a, String b, String c) {
        String ans = "";
        char turn = 'a';
        int an = a.length();
        int bn = b.length();
        int cn = c.length();
        while (true) {
            if (turn == 'a') {
                if (an == 0) {
                    ans = "A";
                    break;
                }
                turn = a.charAt(a.length() - an);
                an--;
            }

            if (turn == 'b') {
                if (bn == 0) {
                    ans = "B";
                    break;
                }
                turn = b.charAt(b.length() - bn);
                bn--;
            }

            if (turn == 'c') {
                if (cn == 0) {
                    ans = "C";
                    break;
                }

                turn = c.charAt(c.length() - cn);
                cn--;
            }
        }
        Main.output.append(ans);
    }
}