import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Deque<String> a = new ArrayDeque<>();
        Deque<String> b = new ArrayDeque<>();
        Deque<String> c = new ArrayDeque<>();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            a.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            b.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            c.add(s.substring(i, i + 1));
        }
        sc.close();
        String card = a.poll();
        while (true) {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        }
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Deque<String> a = new ArrayDeque<>();
        Deque<String> b = new ArrayDeque<>();
        Deque<String> c = new ArrayDeque<>();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            a.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            b.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            c.add(s.substring(i, i + 1));
        }
        sc.close();
        String card = a.poll();
        while (true) {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Deque<String> a = new ArrayDeque<>();
        Deque<String> b = new ArrayDeque<>();
        Deque<String> c = new ArrayDeque<>();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            a.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            b.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            c.add(s.substring(i, i + 1));
        }
        sc.close();
        String card = a.poll();
        while (true) {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        Deque<String> a = new ArrayDeque<>();
        Deque<String> b = new ArrayDeque<>();
        Deque<String> c = new ArrayDeque<>();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            a.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            b.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            c.add(s.substring(i, i + 1));
        }
        sc.close();
        String card = a.poll();
        while (true) {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Deque<String> a = new ArrayDeque<>(); a new ArrayDeque<>() Deque<String> b = new ArrayDeque<>(); b new ArrayDeque<>() Deque<String> c = new ArrayDeque<>(); c new ArrayDeque<>() String s = sc.next(); s sc.next() sc.next sc for (int i = 0; i < s.length(); i++) {
            a.add(s.substring(i, i + 1));
        } int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
            a.add(s.substring(i, i + 1));
        } {
            a.add(s.substring(i, i + 1));
        } a.add(s.substring(i, i + 1)) a.add a s.substring(i, i + 1) s.substring s i i + 1 i 1 s = sc.next() s sc.next() sc.next sc for (int i = 0; i < s.length(); i++) {
            b.add(s.substring(i, i + 1));
        } int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
            b.add(s.substring(i, i + 1));
        } {
            b.add(s.substring(i, i + 1));
        } b.add(s.substring(i, i + 1)) b.add b s.substring(i, i + 1) s.substring s i i + 1 i 1 s = sc.next() s sc.next() sc.next sc for (int i = 0; i < s.length(); i++) {
            c.add(s.substring(i, i + 1));
        } int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
            c.add(s.substring(i, i + 1));
        } {
            c.add(s.substring(i, i + 1));
        } c.add(s.substring(i, i + 1)) c.add c s.substring(i, i + 1) s.substring s i i + 1 i 1 sc.close() sc.close sc String card = a.poll(); card a.poll() a.poll a while (true) {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        } true {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        } if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            } "a".equals(card) "a".equals "a" card {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } if (a.size() == 0) {
                    System.out.println("A");
                    return;
                } a.size() == 0 a.size() a.size a 0 {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; card = a.poll() card a.poll() a.poll a if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            } "b".equals(card) "b".equals "b" card {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } if (b.size() == 0) {
                    System.out.println("B");
                    return;
                } b.size() == 0 b.size() b.size b 0 {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; card = b.poll() card b.poll() b.poll b {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            } if (c.size() == 0) {
                    System.out.println("C");
                    return;
                } c.size() == 0 c.size() c.size c 0 {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; card = c.poll() card c.poll() c.poll c String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Deque<String> a = new ArrayDeque<>();
        Deque<String> b = new ArrayDeque<>();
        Deque<String> c = new ArrayDeque<>();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            a.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            b.add(s.substring(i, i + 1));
        }
        s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            c.add(s.substring(i, i + 1));
        }
        sc.close();
        String card = a.poll();
        while (true) {
            if ("a".equals(card)) {
                if (a.size() == 0) {
                    System.out.println("A");
                    return;
                }
                card = a.poll();
            } else if ("b".equals(card)) {
                if (b.size() == 0) {
                    System.out.println("B");
                    return;
                }
                card = b.poll();
            } else {
                if (c.size() == 0) {
                    System.out.println("C");
                    return;
                }
                card = c.poll();
            }
        }
    }
}