import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    }
 
    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    }
 
    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    } main {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String Sa = scan.next(); Sa scan.next() scan.next scan String Sb = scan.next(); Sb scan.next() scan.next scan String Sc = scan.next(); Sc scan.next() scan.next scan boolean ok = true; ok true char turn = 'a'; turn 'a' char win = 'a'; win 'a' while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        } ok {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        } switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            } turn case 'a': 'a' case 'a': if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    } Sa.equals(" ") Sa.equals Sa " " {
                        win = 'A';
                        ok = false;
                    } win = 'A' win 'A' ok = false ok false {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    } turn = Sa.charAt(0) turn Sa.charAt(0) Sa.charAt Sa 0 Sa = ret(Sa) Sa ret(Sa) ret Sa break; case 'b': 'b' case 'b': if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    } Sb.equals(" ") Sb.equals Sb " " {
                        win = 'B';
                        ok = false;
                    } win = 'B' win 'B' ok = false ok false {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    } turn = Sb.charAt(0) turn Sb.charAt(0) Sb.charAt Sb 0 Sb = ret(Sb) Sb ret(Sb) ret Sb break; case 'c': 'c' case 'c': if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    } Sc.equals(" ") Sc.equals Sc " " {
                        win = 'C';
                        ok = false;
                    } win = 'C' win 'C' ok = false ok false {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    } turn = Sc.charAt(0) turn Sc.charAt(0) Sc.charAt Sc 0 Sc = ret(Sc) Sc ret(Sc) ret Sc break; System.out.println(win) System.out.println System.out System System.out win String[] args args public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    } ret {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    } if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        } str.length() != 1 str.length() str.length str 1 {
            return str.substring(1);
        } return str.substring(1); str.substring(1) str.substring str 1 {
            return " ";
        } return " "; " " String str str public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    }
 
    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    }
 
    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
 
        boolean ok = true;
        char turn = 'a';
        char win = 'a';
 
        while (ok) {
            switch (turn) {
                case 'a':
                    if (Sa.equals(" ")){
                        win = 'A';
                        ok = false;
                    }else {
                        turn = Sa.charAt(0);
                        Sa = ret(Sa);
                    }
                    break;
                case 'b':
                    if (Sb.equals(" ")){
                        win = 'B';
                        ok = false;
                    }else {
                        turn = Sb.charAt(0);
                        Sb = ret(Sb);
                    }
                    break;
                case 'c':
                    if (Sc.equals(" ")){
                        win = 'C';
                        ok = false;
                    }else {
                        turn = Sc.charAt(0);
                        Sc = ret(Sc);
                    }
                    break;
            }
 
        }
        System.out.println(win);
    }
 
    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
}