import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private static char[] a;
	private static int aIndex = 0;
	private static char[] b;
	private static int bIndex = 0;
	private static char[] c;
	private static int cIndex = 0;
	
	private static char winner;
	
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	}
	
	private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	private static char[] a;
	private static int aIndex = 0;
	private static char[] b;
	private static int bIndex = 0;
	private static char[] c;
	private static int cIndex = 0;
	
	private static char winner;
	
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	}
	
	private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	}
} Main private static char[] a; a private static int aIndex = 0; aIndex 0 private static char[] b; b private static int bIndex = 0; bIndex 0 private static char[] c; c private static int cIndex = 0; cIndex 0 private static char winner; winner public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	} main {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	} try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		} {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String line = reader.readLine(); line reader.readLine() reader.readLine reader a = line.toCharArray() a line.toCharArray() line.toCharArray line line = reader.readLine() line reader.readLine() reader.readLine reader b = line.toCharArray() b line.toCharArray() line.toCharArray line line = reader.readLine() line reader.readLine() reader.readLine reader c = line.toCharArray() c line.toCharArray() line.toCharArray line char input = a[0]; input a[0] a 0 aIndex++ aIndex culculate(input) culculate input System.out.println(winner) System.out.println System.out System System.out winner String[] args args private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	} culculate {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	} char nextChar; nextChar switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		} input case 'a' : 'a' case 'a' : if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			} aIndex == a.length aIndex a.length a a.length {
				winner = 'A';
				return;
			} winner = 'A' winner 'A' return; {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			} nextChar = a[aIndex] nextChar a[aIndex] a aIndex aIndex++ aIndex culculate(nextChar) culculate nextChar return; case 'b' : 'b' case 'b' : if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			} bIndex == b.length bIndex b.length b b.length {
				winner = 'B';
				return;
			} winner = 'B' winner 'B' return; {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			} nextChar = b[bIndex] nextChar b[bIndex] b bIndex bIndex++ bIndex culculate(nextChar) culculate nextChar return; case 'c' : 'c' case 'c' : if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			} cIndex == c.length cIndex c.length c c.length {
				winner = 'C';
				return;
			} winner = 'C' winner 'C' return; {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			} nextChar = c[cIndex] nextChar c[cIndex] c cIndex cIndex++ cIndex culculate(nextChar) culculate nextChar return; default : default : throw new RuntimeException(); new RuntimeException() char input input public class Main {
	private static char[] a;
	private static int aIndex = 0;
	private static char[] b;
	private static int bIndex = 0;
	private static char[] c;
	private static int cIndex = 0;
	
	private static char winner;
	
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	}
	
	private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	}
} public class Main {
	private static char[] a;
	private static int aIndex = 0;
	private static char[] b;
	private static int bIndex = 0;
	private static char[] c;
	private static int cIndex = 0;
	
	private static char winner;
	
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	}
	
	private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private static char[] a;
	private static int aIndex = 0;
	private static char[] b;
	private static int bIndex = 0;
	private static char[] c;
	private static int cIndex = 0;
	
	private static char winner;
	
	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String line = reader.readLine();
			a = line.toCharArray();
			line = reader.readLine();
			b = line.toCharArray();
			line = reader.readLine();
			c = line.toCharArray();
		}
		char input = a[0];
		aIndex++;
		culculate(input);
		System.out.println(winner);
	}
	
	private static void culculate(char input) {
		char nextChar;
		switch (input) {
		case 'a' :
			if (aIndex == a.length) {
				winner = 'A';
				return;
			} else {
				nextChar = a[aIndex];
				aIndex++;
				culculate(nextChar);
				return;
			}
		case 'b' :
			if (bIndex == b.length) {
				winner = 'B';
				return;
			} else {
				nextChar = b[bIndex];
				bIndex++;
				culculate(nextChar);
				return;
			}
		case 'c' :
			if (cIndex == c.length) {
				winner = 'C';
				return;
			} else {
				nextChar = c[cIndex];
				cIndex++;
				culculate(nextChar);
				return;
			}
			default : throw new RuntimeException();
		}
	}
}
