import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    } main {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc String s = "a"; s "a" for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        } int i = 0; int i = 0; i 0 i < 301 i 301 i++ i++ i {
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        } {
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        } if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            } s.equals("a") s.equals s "a" {
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            } if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                } a.isEmpty() a.isEmpty a {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; {
                	s = a.substring(0,1);
            		a = a.substring(1);
                } s = a.substring(0,1) s a.substring(0,1) a.substring a 0 1 a = a.substring(1) a a.substring(1) a.substring a 1 if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            } s.equals("b") s.equals s "b" {
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            } if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                } b.isEmpty() b.isEmpty b {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; {
                	s = b.substring(0,1);
            		b = b.substring(1);
                } s = b.substring(0,1) s b.substring(0,1) b.substring b 0 1 b = b.substring(1) b b.substring(1) b.substring b 1 if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            } s.equals("c") s.equals s "c" {
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            } if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                } c.isEmpty() c.isEmpty c {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; {
                	s = c.substring(0,1);
            		c = c.substring(1);
                } s = c.substring(0,1) s c.substring(0,1) c.substring c 0 1 c = c.substring(1) c c.substring(1) c.substring c 1 String[] args args public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    }
} public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    }
} Main
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String s = "a";
        for(int i = 0; i < 301; i++){
        	if(s.equals("a")){
                if(a.isEmpty()){
                    System.out.println("A");
                    return;
                }else{
                	s = a.substring(0,1);
            		a = a.substring(1);
                }
            }else if(s.equals("b")){
            	if(b.isEmpty()){
                    System.out.println("B");
                    return;
                }else{
                	s = b.substring(0,1);
            		b = b.substring(1);
                }
            }else if(s.equals("c")){
            	if(c.isEmpty()){
                    System.out.println("C");
                    return;
                }else{
                	s = c.substring(0,1);
            		c = c.substring(1);
                }
            }
        }
    }
}