import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	}
} import java.util.ArrayList; ArrayList 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);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	} main {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) ArrayList<Integer> num = new ArrayList<Integer>(); num new ArrayList<Integer>() ArrayList<String> param = new ArrayList<String>(); param new ArrayList<String>() int system = 0; system 0 while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		} sc.hasNext() sc.hasNext sc {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		} if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			} sc.hasNextInt() sc.hasNextInt sc {
				num.add(sc.nextInt());
			} num.add(sc.nextInt()) num.add num sc.nextInt() sc.nextInt sc {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			} if (system == 0)
					param.add(sc.next()); system == 0 system 0 param.add(sc.next()) param.add param sc.next() sc.next sc if (system == 1)
					param.add(sc.nextLine()); system == 1 system 1 param.add(sc.nextLine()) param.add param sc.nextLine() sc.nextLine sc Method(num, param) Method num param String[] args args static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	} Method {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	} int turn = 0; turn 0 char target = 'a'; target 'a' while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		} true {
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		} if(param.get(turn).length() == 0) break; param.get(turn).length() == 0 param.get(turn).length() param.get(turn).length param.get(turn) param.get param turn 0 break; target = param.get(turn).charAt(0) target param.get(turn).charAt(0) param.get(turn).charAt param.get(turn) param.get param turn 0 param.set(turn,param.get(turn).substring(1)) param.set param turn param.get(turn).substring(1) param.get(turn).substring param.get(turn) param.get param turn 1 if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			} target == 'a' target 'a' {
				turn = 0;
			} turn = 0 turn 0 if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			} target == 'b' target 'b' {
				turn = 1;
			} turn = 1 turn 1 if(target == 'c'){
				turn = 2;
			} target == 'c' target 'c' {
				turn = 2;
			} turn = 2 turn 2 System.out.println(Character.toUpperCase(target)) System.out.println System.out System System.out Character.toUpperCase(target) Character.toUpperCase Character target ArrayList<Integer> num num ArrayList<String> param param public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int turn = 0;
		char target = 'a';

		while(true){
			if(param.get(turn).length() == 0) break;
			target = param.get(turn).charAt(0);
			param.set(turn,param.get(turn).substring(1));
			
			if(target == 'a'){
				turn = 0;
			}else if(target == 'b'){
				turn = 1;
			}else if(target == 'c'){
				turn = 2;
			}
		}
		System.out.println(Character.toUpperCase(target));
	}
}