
import java.io.*;
import java.util.*;
//import java.util.stream.*;;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
} Main public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    } main {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); bw new BufferedWriter(new OutputStreamWriter(System.out)) Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder a = new StringBuilder(br.readLine()); a new StringBuilder(br.readLine()) StringBuilder b = new StringBuilder(br.readLine()); b new StringBuilder(br.readLine()) StringBuilder c = new StringBuilder(br.readLine()); c new StringBuilder(br.readLine()) String s = ""; s "" char x = a.charAt(0); x a.charAt(0) a.charAt a 0 while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        } true {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        } if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            } x == 'a' x 'a' {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                } a.length() == 0 a.length() a.length a 0 {
                    s = "A";
                    break;
                } s = "A" s "A" break; {
                    x = a.charAt(0);
                    a.delete(0, 1);
                } x = a.charAt(0) x a.charAt(0) a.charAt a 0 a.delete(0, 1) a.delete a 0 1 if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            } x == 'b' x 'b' {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                } b.length() == 0 b.length() b.length b 0 {
                    s = "B";
                    break;
                } s = "B" s "B" break; {
                    x = b.charAt(0);
                    b.delete(0, 1);
                } x = b.charAt(0) x b.charAt(0) b.charAt b 0 b.delete(0, 1) b.delete b 0 1 if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            } x == 'c' x 'c' {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            } if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                } c.length() == 0 c.length() c.length c 0 {
                    s = "C";
                    break;
                } s = "C" s "C" break; {
                    x = c.charAt(0);
                    c.delete(0, 1);
                } x = c.charAt(0) x c.charAt(0) c.charAt c 0 c.delete(0, 1) c.delete c 0 1 System.out.println(s) System.out.println System.out System System.out s bw.flush() bw.flush bw String[] args args public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
} public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
} Main

import java.io.*;
import java.util.*;
//import java.util.stream.*;;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
}
