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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	}
} 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) {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	} main {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) @SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3]; queue new Queue[3] 3 queue[0] = new ArrayDeque<Integer>() queue[0] queue 0 new ArrayDeque<Integer>() queue[1] = new ArrayDeque<Integer>() queue[1] queue 1 new ArrayDeque<Integer>() queue[2] = new ArrayDeque<Integer>() queue[2] queue 2 new ArrayDeque<Integer>() for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		} int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		} {
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		} String str = sc.next(); str sc.next() sc.next sc for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			} int j = 0; int j = 0; j 0 j < str.length() j str.length() str.length str j++ j++ j {
				queue[i].add(str.charAt(j) - 'a');
			} {
				queue[i].add(str.charAt(j) - 'a');
			} queue[i].add(str.charAt(j) - 'a') queue[i].add queue[i] queue i str.charAt(j) - 'a' str.charAt(j) str.charAt str j 'a' int player = 0; player 0 while(queue[player].size() != 0){
			player = queue[player].poll();
		} queue[player].size() != 0 queue[player].size() queue[player].size queue[player] queue player 0 {
			player = queue[player].poll();
		} player = queue[player].poll() player queue[player].poll() queue[player].poll queue[player] queue player System.out.println((char)(player + 'A')) System.out.println System.out System System.out (char)(player + 'A') player 'A' String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	}
} Main

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		@SuppressWarnings("unchecked")
		Queue<Integer>[] queue = new Queue[3];
		queue[0] = new ArrayDeque<Integer>();
		queue[1] = new ArrayDeque<Integer>();
		queue[2] = new ArrayDeque<Integer>();

		for(int i = 0; i < 3; i++){
			String str = sc.next();
			for(int j = 0; j < str.length(); j++){
				queue[i].add(str.charAt(j) - 'a');
			}

//			System.out.println(queue[i].size());
		}

		int player = 0;
		while(queue[player].size() != 0){
			player = queue[player].poll();
		}

		System.out.println((char)(player + 'A'));
	}
}