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;
    String A;
    String B;
    String C;
    int countA = 0;
    int countB = -1;
    int countC = -1;
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} 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;
    String A;
    String B;
    String C;
    int countA = 0;
    int countB = -1;
    int countC = -1;
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} Main //フィールド
    Scanner sc; sc String A; A String B; B String C; C int countA = 0; countA 0 int countB = -1; countB -1 1 int countC = -1; countC -1 1 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 = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    } Main {
        this.sc = sc;
        this.A = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    } this.sc = sc this.sc this this.sc sc this.A = sc.next() this.A this this.A sc.next() sc.next sc this.B = sc.next() this.B this this.B sc.next() sc.next sc this.C = sc.next() this.C this this.C sc.next() sc.next sc Scanner sc sc //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    } solve {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    } String answer = null; answer null while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        } true {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        } if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	} next == 'a' next 'a' {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} countA++ countA if (A.length() == countA) {
            		answer = "A";
            		break;
            	} A.length() == countA A.length() A.length A countA {
            		answer = "A";
            		break;
            	} answer = "A" answer "A" break; next = A.charAt(countA) next A.charAt(countA) A.charAt A countA if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	} next == 'b' next 'b' {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} countB++ countB if (B.length() == countB) {
            		answer = "B";
            		break;
            	} B.length() == countB B.length() B.length B countB {
            		answer = "B";
            		break;
            	} answer = "B" answer "B" break; next = B.charAt(countB) next B.charAt(countB) B.charAt B countB if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	} next == 'c' next 'c' {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	} countC++ countC if (C.length() == countC) {
            		answer = "C";
            		break;
            	} C.length() == countC C.length() C.length C countC {
            		answer = "C";
            		break;
            	} answer = "C" answer "C" break; next = C.charAt(countC) next C.charAt(countC) C.charAt C countC return answer; answer //出力
    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;
    String A;
    String B;
    String C;
    int countA = 0;
    int countB = -1;
    int countC = -1;
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    }
    
    //出力
    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;
    String A;
    String B;
    String C;
    int countA = 0;
    int countB = -1;
    int countC = -1;
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

} Main
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;
    String A;
    String B;
    String C;
    int countA = 0;
    int countB = -1;
    int countC = -1;
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.next();
        this.B = sc.next();
        this.C = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		countA++;
        		if (A.length() == countA) {
            		answer = "A";
            		break;
            	}
        		next = A.charAt(countA);
        	} else if (next == 'b') {
        		countB++;
        		if (B.length() == countB) {
            		answer = "B";
            		break;
            	}
        		next = B.charAt(countB);
        	} else if (next == 'c') {
        		countC++;
        		if (C.length() == countC) {
            		answer = "C";
            		break;
            	}
        		next = C.charAt(countC);
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}
