import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    Queue<String> A = new ArrayDeque<String>();
    Queue<String> B = new ArrayDeque<String>();
    Queue<String> C = new ArrayDeque<String>();
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    }
    
    //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    }
    
    //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    Queue<String> A = new ArrayDeque<String>();
    Queue<String> B = new ArrayDeque<String>();
    Queue<String> C = new ArrayDeque<String>();
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    }
    
    //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    }
    
    //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} Main //フィールド
    Scanner sc; sc Queue<String> A = new ArrayDeque<String>(); A new ArrayDeque<String>() Queue<String> B = new ArrayDeque<String>(); B new ArrayDeque<String>() Queue<String> C = new ArrayDeque<String>(); C new ArrayDeque<String>() char next = 'a'; next 'a' public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Main m = new Main(sc); m new Main(sc) m.show(m.solve()) m.show m m.solve() m.solve m sc.close() sc.close sc String[] args args //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    } Main {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    } this.sc = sc this.sc this this.sc sc this.A = read() this.A this this.A read() read this.B = read() this.B this this.B read() read this.C = read() this.C this this.C read() read Scanner sc sc //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    } read {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    } Queue<String> tmp = new ArrayDeque<String>(); tmp new ArrayDeque<String>() String S = sc.next(); S sc.next() sc.next sc for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	} int i=0; int i=0; i 0 i<S.length() i S.length() S.length S i++ i++ i {
    		tmp.add(String.valueOf(S.charAt(i)));
    	} {
    		tmp.add(String.valueOf(S.charAt(i)));
    	} tmp.add(String.valueOf(S.charAt(i))) tmp.add tmp String.valueOf(S.charAt(i)) String.valueOf String S.charAt(i) S.charAt S i return tmp; tmp //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    } solve {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    } String answer = null; answer null while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        } true {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        } if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	} next == 'a' next 'a' {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} if (A.size() == 0) {
            		answer = "A";
            		break;
            	} A.size() == 0 A.size() A.size A 0 {
            		answer = "A";
            		break;
            	} answer = "A" answer "A" break; play(A) play A if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	} next == 'b' next 'b' {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} if (B.size() == 0) {
            		answer = "B";
            		break;
            	} B.size() == 0 B.size() B.size B 0 {
            		answer = "B";
            		break;
            	} answer = "B" answer "B" break; play(B) play B if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	} next == 'c' next 'c' {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	} if (C.size() == 0) {
            		answer = "C";
            		break;
            	} C.size() == 0 C.size() C.size C 0 {
            		answer = "C";
            		break;
            	} answer = "C" answer "C" break; play(C) play C return answer; answer //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    } play {
    	next = tmp.poll().charAt(0);
    	return tmp;
    } next = tmp.poll().charAt(0) next tmp.poll().charAt(0) tmp.poll().charAt tmp.poll() tmp.poll tmp 0 return tmp; tmp Queue<String> tmp tmp //出力
    public void show(String answer) {
        System.out.println(answer);
    } show {
        System.out.println(answer);
    } System.out.println(answer) System.out.println System.out System System.out answer String answer answer public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    Queue<String> A = new ArrayDeque<String>();
    Queue<String> B = new ArrayDeque<String>();
    Queue<String> C = new ArrayDeque<String>();
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    }
    
    //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    }
    
    //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    Queue<String> A = new ArrayDeque<String>();
    Queue<String> B = new ArrayDeque<String>();
    Queue<String> C = new ArrayDeque<String>();
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    }
    
    //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    }
    
    //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    Queue<String> A = new ArrayDeque<String>();
    Queue<String> B = new ArrayDeque<String>();
    Queue<String> C = new ArrayDeque<String>();
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    }
    
    //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    }
    
    //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}
