import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.lang.reflect.Array; Array java.lang.reflect import java.util.ArrayDeque; ArrayDeque java.util import java.util.Arrays; Arrays java.util import java.util.Deque; Deque java.util public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    }

} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] a_list = br.readLine().split(""); a_list br.readLine().split("") br.readLine().split br.readLine() br.readLine br "" String[] b_list = br.readLine().split(""); b_list br.readLine().split("") br.readLine().split br.readLine() br.readLine br "" String[] c_list = br.readLine().split(""); c_list br.readLine().split("") br.readLine().split br.readLine() br.readLine br "" Deque<String> a a b b c; c a = new ArrayDeque<String>(Arrays.asList(a_list)) a new ArrayDeque<String>(Arrays.asList(a_list)) b = new ArrayDeque<String>(Arrays.asList(b_list)) b new ArrayDeque<String>(Arrays.asList(b_list)) c = new ArrayDeque<String>(Arrays.asList(c_list)) c new ArrayDeque<String>(Arrays.asList(c_list)) String turn = "a"; turn "a" while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        } turn != null turn null {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        } switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            } turn case "a": "a" case "a": turn = a.poll() turn a.poll() a.poll a if (turn == null) System.out.println("A"); turn == null turn null System.out.println("A") System.out.println System.out System System.out "A" break; case "b": "b" case "b": turn = b.poll() turn b.poll() b.poll b if (turn == null) System.out.println("B"); turn == null turn null System.out.println("B") System.out.println System.out System System.out "B" break; case "c": "c" case "c": turn = c.poll() turn c.poll() c.poll c if (turn == null) System.out.println("C"); turn == null turn null System.out.println("C") System.out.println System.out System System.out "C" break; String[] args args public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    }

} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a_list = br.readLine().split("");
        String[] b_list = br.readLine().split("");
        String[] c_list = br.readLine().split("");

        Deque<String> a, b, c;
        a = new ArrayDeque<String>(Arrays.asList(a_list));
        b = new ArrayDeque<String>(Arrays.asList(b_list));
        c = new ArrayDeque<String>(Arrays.asList(c_list));

        String turn = "a";
        while (turn != null) {
            switch (turn) {
                case "a":
                    turn = a.poll();
                    if (turn == null) System.out.println("A");
                    break;
                case "b":
                    turn = b.poll();
                    if (turn == null) System.out.println("B");
                    break;
                case "c":
                    turn = c.poll();
                    if (turn == null) System.out.println("C");
                    break;
            }
        }
    }

}
