import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String SA = sc.next(); SA sc.next() sc.next sc String[] a = SA.split(""); a SA.split("") SA.split SA "" String SB = sc.next(); SB sc.next() sc.next sc String[] b = SB.split(""); b SB.split("") SB.split SB "" String SC = sc.next(); SC sc.next() sc.next sc String[] c = SC.split(""); c SC.split("") SC.split SC "" Deque<String> aque = new ArrayDeque<>(); aque new ArrayDeque<>() for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        } int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
            aque.add(a[i]);
        } {
            aque.add(a[i]);
        } aque.add(a[i]) aque.add aque a[i] a i Deque<String> bque = new ArrayDeque<>(); bque new ArrayDeque<>() for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        } int i=0; int i=0; i 0 i<b.length i b.length b b.length i++ i++ i {
            bque.add(b[i]);
        } {
            bque.add(b[i]);
        } bque.add(b[i]) bque.add bque b[i] b i Deque<String> cque = new ArrayDeque<>(); cque new ArrayDeque<>() for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        } int i=0; int i=0; i 0 i<c.length i c.length c c.length i++ i++ i {
            cque.add(c[i]);
        } {
            cque.add(c[i]);
        } cque.add(c[i]) cque.add cque c[i] c i String now = "a"; now "a" while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        } true {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        } if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            } now.equals("a") now.equals now "a" {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            } if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                } aque.size() == 0 aque.size() aque.size aque 0 {
                    System.out.println("A");
                    break;
                } System.out.println("A") System.out.println System.out System System.out "A" break; now = aque.poll() now aque.poll() aque.poll aque if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            } now.equals("b") now.equals now "b" {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            } if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                } bque.size() == 0 bque.size() bque.size bque 0 {
                    System.out.println("B");
                    break;
                } System.out.println("B") System.out.println System.out System System.out "B" break; now = bque.poll() now bque.poll() bque.poll bque {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            } if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                } cque.size() == 0 cque.size() cque.size cque 0 {
                    System.out.println("C");
                    break;
                } System.out.println("C") System.out.println System.out System System.out "C" break; now = cque.poll() now cque.poll() cque.poll cque String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String[] a = SA.split("");
        String SB = sc.next();
        String[] b = SB.split("");
        String SC = sc.next();
        String[] c = SC.split("");
        
        Deque<String> aque = new ArrayDeque<>();
        for(int i=0; i<a.length; i++) {
            aque.add(a[i]);
        }
        Deque<String> bque = new ArrayDeque<>();
        for(int i=0; i<b.length; i++) {
            bque.add(b[i]);
        }
        Deque<String> cque = new ArrayDeque<>();
        for(int i=0; i<c.length; i++) {
            cque.add(c[i]);
        }
        
        String now = "a";
        while(true) {
            if(now.equals("a")) {
                if(aque.size() == 0) {
                    System.out.println("A");
                    break;
                }
                now = aque.poll();
            }else if(now.equals("b")) {
                if(bque.size() == 0) {
                    System.out.println("B");
                    break;
                }
                now = bque.poll();
                
            }else {
                if(cque.size() == 0) {
                    System.out.println("C");
                    break;
                }
                now = cque.poll();
                
            }
        }
    }
}
