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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	}
	static class Player{
		private Queue<Character> cards;
		
		public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		}		
	}
} 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 scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	}
	static class Player{
		private Queue<Character> cards;
		
		public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		}		
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String ans = "NONE"; ans "NONE" Player a = new Player(scanner.next().toCharArray()); a new Player(scanner.next().toCharArray()) Player b = new Player(scanner.next().toCharArray()); b new Player(scanner.next().toCharArray()) Player c = new Player(scanner.next().toCharArray()); c new Player(scanner.next().toCharArray()) char nc = a.cards.poll(); nc a.cards.poll() a.cards.poll a.cards a a.cards while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		} true {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		} if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			} nc == 'a' nc 'a' {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			} if (a.cards.isEmpty()) {
					ans = "A";
					break;
				} a.cards.isEmpty() a.cards.isEmpty a.cards a a.cards {
					ans = "A";
					break;
				} ans = "A" ans "A" break; nc = a.cards.poll() nc a.cards.poll() a.cards.poll a.cards a a.cards if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			} nc == 'b' nc 'b' {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			} if (b.cards.isEmpty()) {
					ans = "B";
					break;
				} b.cards.isEmpty() b.cards.isEmpty b.cards b b.cards {
					ans = "B";
					break;
				} ans = "B" ans "B" break; nc = b.cards.poll() nc b.cards.poll() b.cards.poll b.cards b b.cards if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			} nc == 'c' nc 'c' {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			} if (c.cards.isEmpty()) {
					ans = "C";
					break;
				} c.cards.isEmpty() c.cards.isEmpty c.cards c c.cards {
					ans = "C";
					break;
				} ans = "C" ans "C" break; nc = c.cards.poll() nc c.cards.poll() c.cards.poll c.cards c c.cards System.out.println(ans) System.out.println System.out System System.out ans scanner.close() scanner.close scanner String[] args args static class Player{
		private Queue<Character> cards;
		
		public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		}		
	} Player private Queue<Character> cards; cards public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		} Player {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		} cards = new ArrayDeque<Character>() cards new ArrayDeque<Character>() for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			} int i = 0; int i = 0; i 0 i < source.length i source.length source source.length i++ i++ i {
				cards.add(source[i]);
			} {
				cards.add(source[i]);
			} cards.add(source[i]) cards.add cards source[i] source i char[] source source public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	}
	static class Player{
		private Queue<Character> cards;
		
		public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		}		
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	}
	static class Player{
		private Queue<Character> cards;
		
		public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		}		
	}
} Main
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String ans = "NONE";
		
		Player a = new Player(scanner.next().toCharArray());
		Player b = new Player(scanner.next().toCharArray());
		Player c = new Player(scanner.next().toCharArray());
		
		
		char nc = a.cards.poll();
		while (true) {
			if (nc == 'a') {
				if (a.cards.isEmpty()) {
					ans = "A";
					break;
				}
				nc = a.cards.poll();	
			}else if (nc == 'b') {
				if (b.cards.isEmpty()) {
					ans = "B";
					break;
				}
				nc = b.cards.poll();
			}else if (nc == 'c') {
				if (c.cards.isEmpty()) {
					ans = "C";
					break;
				}
				nc = c.cards.poll();
			}
		}
		System.out.println(ans);
		
		scanner.close();
	}
	static class Player{
		private Queue<Character> cards;
		
		public Player(char[] source) {
			cards = new ArrayDeque<Character>();
			for (int i = 0; i < source.length; i++) {
				cards.add(source[i]);
			}
		}		
	}
}