import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	}
} Main public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	} main {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	} @SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String[] s = { scan.next(), scan.next(), scan.next() }; s { scan.next(), scan.next(), scan.next() } scan.next() scan.next scan scan.next() scan.next scan scan.next() scan.next scan int[] index = { 0, 0, 0 }; index { 0, 0, 0 } 0 0 0 int turn = 0; turn 0 char next; next while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		} true {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		} if (s[turn].length() == index[turn]) {
				break;
			} s[turn].length() == index[turn] s[turn].length() s[turn].length s[turn] s turn index[turn] index turn {
				break;
			} break; next = s[turn].charAt(index[turn]) next s[turn].charAt(index[turn]) s[turn].charAt s[turn] s turn index[turn] index turn index[turn]++ index[turn] index turn switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			} next case 'a': 'a' case 'a': turn = 0 turn 0 break; case 'b': 'b' case 'b': turn = 1 turn 1 break; case 'c': 'c' case 'c': turn = 2 turn 2 break; switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		} turn case 0: 0 case 0: System.out.println("A") System.out.println System.out System System.out "A" break; case 1: 1 case 1: System.out.println("B") System.out.println System.out System System.out "B" break; case 2: 2 case 2: System.out.println("C") System.out.println System.out System System.out "C" break; String[] args args public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	}
} public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String[] s = { scan.next(), scan.next(), scan.next() };
		int[] index = { 0, 0, 0 };

		int turn = 0;
		char next;
		while (true) {
			if (s[turn].length() == index[turn]) {
				break;
			}
			next = s[turn].charAt(index[turn]);
			index[turn]++;
			switch (next) {
			case 'a':
				turn = 0;
				break;
			case 'b':
				turn = 1;
				break;
			case 'c':
				turn = 2;
				break;
			}
		}
		switch (turn) {
		case 0:
			System.out.println("A");
			break;
		case 1:
			System.out.println("B");
			break;
		case 2:
			System.out.println("C");
			break;
		}
	}
}
