import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] a = sc.next().toCharArray(); a sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] b = sc.next().toCharArray(); b sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int indA = 1; indA 1 int indB = 0; indB 0 int indC = 0; indC 0 char now = 'a'; now 'a' while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        } indA <= a.length && indB <= b.length && indC <= c.length indA <= a.length && indB <= b.length && indC <= c.length indA <= a.length indA a.length a a.length indB <= b.length indB b.length b b.length indC <= c.length indC c.length c c.length {
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        } if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            } now == 'a' now 'a' {
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            } if(indA == a.length){
                    System.out.println("A");
                    return;
                } indA == a.length indA a.length a a.length {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; indA++ indA now = a[indA-1] now a[indA-1] a indA-1 indA 1 if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            } now == 'b' now 'b' {
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            } if(indB == b.length){
                    System.out.println("B");
                    return;
                } indB == b.length indB b.length b b.length {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; indB++ indB now = b[indB-1] now b[indB-1] b indB-1 indB 1 {
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            } if(indC == c.length){
                    System.out.println("C");
                    return;
                } indC == c.length indC c.length c c.length {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; indC++ indC now = c[indC-1] now c[indC-1] c indC-1 indC 1 String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();
        int indA = 1;
        int indB = 0;
        int indC = 0;
        char now = 'a';
        while(indA <= a.length && indB <= b.length && indC <= c.length){
            if(now == 'a'){
                if(indA == a.length){
                    System.out.println("A");
                    return;
                }
                indA++;
                now = a[indA-1];
            }else if(now == 'b'){
                if(indB == b.length){
                    System.out.println("B");
                    return;
                }
                indB++;
                now = b[indB-1];
            }else{
                if(indC == c.length){
                    System.out.println("C");
                    return;
                }
                indC++;
                now = c[indC-1];
            }
        }
    }
}
