import java.util.*;

public class Main {
    private static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    }
} import java.util.*; util.* java public class Main {
    private static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    }
} Main private static Scanner scn = new Scanner(System.in); scn new Scanner(System.in) public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    } main {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    } String sa = scn.next(); sa scn.next() scn.next scn String sb = scn.next(); sb scn.next() scn.next scn String sc = scn.next(); sc scn.next() scn.next scn int la = sa.length(); la sa.length() sa.length sa int lb = sb.length(); lb sb.length() sb.length sb int lc = sc.length(); lc sc.length() sc.length sc int a = 0; a 0 int b = 0; b 0 int c = 0; c 0 int n = 0; n 0 while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        } true {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        } char t = ' '; t ' ' if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            } n==0 n 0 {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } if (a==la) {
                    System.out.println("A");
                    return;
                } a==la a la {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; t = sa.charAt(a++) t sa.charAt(a++) sa.charAt sa a++ a if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            } n==1 n 1 {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } if (b==lb) {
                    System.out.println("B");
                    return;
                } b==lb b lb {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; t = sb.charAt(b++) t sb.charAt(b++) sb.charAt sb b++ b if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            } n==2 n 2 {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            } if (c==lc) {
                    System.out.println("C");
                    return;
                } c==lc c lc {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; t = sc.charAt(c++) t sc.charAt(c++) sc.charAt sc c++ c if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            } t=='a' t 'a' {
                n = 0;
            } n = 0 n 0 if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            } t=='b' t 'b' {
                n = 1;
            } n = 1 n 1 if (t=='c') {
                n = 2;
            } t=='c' t 'c' {
                n = 2;
            } n = 2 n 2 String[] args args public class Main {
    private static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    }
} public class Main {
    private static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    }
} Main
import java.util.*;

public class Main {
    private static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    }
}
