import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

	} main {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) LinkedList<Character> aCard = new LinkedList<>(); aCard new LinkedList<>() LinkedList<Character> bCard = new LinkedList<>(); bCard new LinkedList<>() LinkedList<Character> cCard = new LinkedList<>(); cCard new LinkedList<>() String aString = scan.next(); aString scan.next() scan.next scan for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		} int i = 0; int i = 0; i 0 i < aString.length() i aString.length() aString.length aString i++ i++ i {
			aCard.add(aString.charAt(i));
		} {
			aCard.add(aString.charAt(i));
		} aCard.add(aString.charAt(i)) aCard.add aCard aString.charAt(i) aString.charAt aString i String bString = scan.next(); bString scan.next() scan.next scan for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		} int i = 0; int i = 0; i 0 i < bString.length() i bString.length() bString.length bString i++ i++ i {
			bCard.add(bString.charAt(i));
		} {
			bCard.add(bString.charAt(i));
		} bCard.add(bString.charAt(i)) bCard.add bCard bString.charAt(i) bString.charAt bString i String cString = scan.next(); cString scan.next() scan.next scan for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		} int i = 0; int i = 0; i 0 i < cString.length() i cString.length() cString.length cString i++ i++ i {
			cCard.add(cString.charAt(i));
		} {
			cCard.add(cString.charAt(i));
		} cCard.add(cString.charAt(i)) cCard.add cCard cString.charAt(i) cString.charAt cString i char turn = aCard.poll(); turn aCard.poll() aCard.poll aCard boolean endFlag = false; endFlag false while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		} true {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		} switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			} turn case 'a': 'a' case 'a': if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				} aCard.size() == 0 aCard.size() aCard.size aCard 0 {
					System.out.println("A");
					endFlag = true;
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" endFlag = true endFlag true break; turn = aCard.poll() turn aCard.poll() aCard.poll aCard break; case 'b': 'b' case 'b': if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				} bCard.size() == 0 bCard.size() bCard.size bCard 0 {
					System.out.println("B");
					endFlag = true;
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" endFlag = true endFlag true break; turn = bCard.poll() turn bCard.poll() bCard.poll bCard break; case 'c': 'c' case 'c': if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				} cCard.size() == 0 cCard.size() cCard.size cCard 0 {
					System.out.println("C");
					endFlag = true;
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" endFlag = true endFlag true break; turn = cCard.poll() turn cCard.poll() cCard.poll cCard if (endFlag) {
				break;
			} endFlag {
				break;
			} break; String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

	}
} Main
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		LinkedList<Character> aCard = new LinkedList<>();
		LinkedList<Character> bCard = new LinkedList<>();
		LinkedList<Character> cCard = new LinkedList<>();

		// input
		String aString = scan.next();
		for (int i = 0; i < aString.length(); i++) {
			aCard.add(aString.charAt(i));
		}
		String bString = scan.next();
		for (int i = 0; i < bString.length(); i++) {
			bCard.add(bString.charAt(i));
		}
		String cString = scan.next();
		for (int i = 0; i < cString.length(); i++) {
			cCard.add(cString.charAt(i));
		}

		// check
		char turn = aCard.poll();
		boolean endFlag = false;
		while (true) {

			switch (turn) {
			case 'a':
				if (aCard.size() == 0) {
					System.out.println("A");
					endFlag = true;
					break;
				}
				turn = aCard.poll();
				break;
			case 'b':
				if (bCard.size() == 0) {
					System.out.println("B");
					endFlag = true;
					break;
				}
				turn = bCard.poll();
				break;
			case 'c':
				if (cCard.size() == 0) {
					System.out.println("C");
					endFlag = true;
					break;
				}
				turn = cCard.poll();
			}

			if (endFlag) {
				break;
			}
		}

	}
}
