import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String [] S = {sc.next(),sc.next(),sc.next()}; S {sc.next(),sc.next(),sc.next()} sc.next() sc.next sc sc.next() sc.next sc sc.next() sc.next sc int [] k = {0,0,0}; k {0,0,0} 0 0 0 int t=0; t 0 while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        } true {
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        } k[t]++ k[t] k t for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            } int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            } {
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            } if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                } k[i]>S[i].length() k[i] k i S[i].length() S[i].length S[i] S i {
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                } char c = (char)('A'+i); c (char)('A'+i) 'A' i String ans = String.valueOf(c); ans String.valueOf(c) String.valueOf String c System.out.println(ans) System.out.println System.out System System.out ans return; t = S[t].charAt(k[t]-1)-'a' t S[t].charAt(k[t]-1)-'a' S[t].charAt(k[t]-1) S[t].charAt S[t] S t k[t]-1 k[t] k t 1 'a' String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] S = {sc.next(),sc.next(),sc.next()};
        int [] k = {0,0,0};
        int t=0;
        while(true){
            k[t]++;
            for(int i=0; i<3; i++){
                if(k[i]>S[i].length()){
                    char c = (char)('A'+i);
                    String ans = String.valueOf(c);
                    System.out.println(ans);
                    return;
                }
            }
            t = S[t].charAt(k[t]-1)-'a';
        }
    }
}
