
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a[]; a int p[]; p p = new int[3] p new int[3] 3 a = new String[3] a new String[3] 3 for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		} int i = 0; int i = 0; i 0 i < 3 i 3 ++i ++i i {
			a[i] = sc.nextLine();
			p[i] = 0;
		} {
			a[i] = sc.nextLine();
			p[i] = 0;
		} a[i] = sc.nextLine() a[i] a i sc.nextLine() sc.nextLine sc p[i] = 0 p[i] p i 0 int turn = 0; turn 0 int win = turn; win turn while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		} p[turn] != a[turn].length() p[turn] p turn a[turn].length() a[turn].length a[turn] a turn {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		} ++p[turn] p[turn] p turn turn = a[turn].charAt(p[turn] - 1) - 'a' turn a[turn].charAt(p[turn] - 1) - 'a' a[turn].charAt(p[turn] - 1) a[turn].charAt a[turn] a turn p[turn] - 1 p[turn] p turn 1 'a' win = turn win turn System.out.println((char)(win + 'A')) System.out.println System.out System System.out (char)(win + 'A') win 'A' sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	}

} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[];
		int p[];
		
		p = new int[3];
		a = new String[3];
		
		for(int i = 0; i < 3; ++i) {
			a[i] = sc.nextLine();
			p[i] = 0;
		}
		
		int turn = 0;
		int win = turn;
		
		while(p[turn] != a[turn].length()) {
			++p[turn];
			turn = a[turn].charAt(p[turn] - 1) - 'a';
			win = turn;
		}
		
		System.out.println((char)(win + 'A'));
		
		sc.close();
	}

}
