import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	}

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

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	}

} Main public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	} main {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String aCards = sc.nextLine(); aCards sc.nextLine() sc.nextLine sc String bCards = sc.nextLine(); bCards sc.nextLine() sc.nextLine sc String cCards = sc.nextLine(); cCards sc.nextLine() sc.nextLine sc int nowTurn = 0; nowTurn 0 int aCardNum = 0; aCardNum 0 int bCardNum = 0; bCardNum 0 int cCardNum = 0; cCardNum 0 int aCardMaxLen = aCards.length(); aCardMaxLen aCards.length() aCards.length aCards int bCardMaxLen = bCards.length(); bCardMaxLen bCards.length() bCards.length bCards int cCardMaxLen = cCards.length(); cCardMaxLen cCards.length() cCards.length cCards char nowChar = 'z'; nowChar 'z' while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		} true {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		} if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			} nowTurn == 0 nowTurn 0 {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} if (aCardNum >= aCardMaxLen) break; // 上がり aCardNum >= aCardMaxLen aCardNum aCardMaxLen break; // 上がり nowChar = aCards.charAt(aCardNum) nowChar aCards.charAt(aCardNum) aCards.charAt aCards aCardNum aCardNum++ aCardNum if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			} nowTurn == 1 nowTurn 1 {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} if (bCardNum >= bCardMaxLen) break; // 上がり bCardNum >= bCardMaxLen bCardNum bCardMaxLen break; // 上がり nowChar = bCards.charAt(bCardNum) nowChar bCards.charAt(bCardNum) bCards.charAt bCards bCardNum bCardNum++ bCardNum if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			} nowTurn == 2 nowTurn 2 {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			} if (cCardNum >= cCardMaxLen) break; // 上がり cCardNum >= cCardMaxLen cCardNum cCardMaxLen break; // 上がり nowChar = cCards.charAt(cCardNum) nowChar cCards.charAt(cCardNum) cCards.charAt cCards cCardNum cCardNum++ cCardNum if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			} 'a' == nowChar 'a' nowChar {
				nowTurn = 0;
			} nowTurn = 0 nowTurn 0 if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			} 'b' == nowChar 'b' nowChar {
				nowTurn = 1;
			} nowTurn = 1 nowTurn 1 if ('c' == nowChar) {
				nowTurn = 2;
			} 'c' == nowChar 'c' nowChar {
				nowTurn = 2;
			} nowTurn = 2 nowTurn 2 System.out.println((char)('A' + nowTurn)) System.out.println System.out System System.out (char)('A' + nowTurn) 'A' nowTurn String[] args args public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	}

} public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String aCards = sc.nextLine();
		String bCards = sc.nextLine();
		String cCards = sc.nextLine();
		
		int nowTurn = 0; // Aさんから開始する
		int aCardNum = 0;
		int bCardNum = 0;
		int cCardNum = 0;
		int aCardMaxLen = aCards.length();
		int bCardMaxLen = bCards.length();
		int cCardMaxLen = cCards.length();
		
		
		char nowChar = 'z'; // 初期化
		
		// 結果が出るまで続ける
		while(true) {
			if(nowTurn == 0) {
				if (aCardNum >= aCardMaxLen) break; // 上がり
				nowChar = aCards.charAt(aCardNum);
				aCardNum++;
			} else if(nowTurn == 1) {
				if (bCardNum >= bCardMaxLen) break; // 上がり
				nowChar = bCards.charAt(bCardNum);
				bCardNum++;
			} else if (nowTurn == 2) {
				if (cCardNum >= cCardMaxLen) break; // 上がり
				nowChar = cCards.charAt(cCardNum);
				cCardNum++;
			}
			
			// 次の番を決める
			if ('a' == nowChar) {
				nowTurn = 0;
			} else if ('b' == nowChar) {
				nowTurn = 1;
			} else if ('c' == nowChar) {
				nowTurn = 2;
			}
		}
		
		// 勝者を表示
		System.out.println((char)('A' + nowTurn));
	}

}
