import java.util.ArrayList;
import java.util.Scanner;

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

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