
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.reflect.Array; Array java.lang.reflect public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
} Main public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	} main {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	} FastReader r = new FastReader(); r new FastReader() Map<String,String> map = new HashMap<>(); map new HashMap<>() map.put("a", r.str()) map.put map "a" r.str() r.str r map.put("b", r.str()) map.put map "b" r.str() r.str r map.put("c", r.str()) map.put map "c" r.str() r.str r String next = "a"; next "a" int Apos = 0; Apos 0 int Bpos = 0; Bpos 0 int Cpos = 0; Cpos 0 while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		} true {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		} if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			} next.equals("a") next.equals next "a" {
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			} if(map.get(next).length() == Apos) {
					print("A");
					return;
				} map.get(next).length() == Apos map.get(next).length() map.get(next).length map.get(next) map.get map next Apos {
					print("A");
					return;
				} print("A") print "A" return; next = ""+map.get(next).charAt(Apos++) next ""+map.get(next).charAt(Apos++) "" map.get(next).charAt(Apos++) map.get(next).charAt map.get(next) map.get map next Apos++ Apos if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			} next.equals("b") next.equals next "b" {
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			} if(map.get(next).length() == Bpos) {
					print("B");
					return;
				} map.get(next).length() == Bpos map.get(next).length() map.get(next).length map.get(next) map.get map next Bpos {
					print("B");
					return;
				} print("B") print "B" return; next = ""+map.get(next).charAt(Bpos++) next ""+map.get(next).charAt(Bpos++) "" map.get(next).charAt(Bpos++) map.get(next).charAt map.get(next) map.get map next Bpos++ Bpos if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			} next.equals("c") next.equals next "c" {
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			} if(map.get(next).length() == Cpos) {
					print("C");
					return;
				} map.get(next).length() == Cpos map.get(next).length() map.get(next).length map.get(next) map.get map next Cpos {
					print("C");
					return;
				} print("C") print "C" return; next = ""+map.get(next).charAt(Cpos++) next ""+map.get(next).charAt(Cpos++) "" map.get(next).charAt(Cpos++) map.get(next).charAt map.get(next) map.get map next Cpos++ Cpos String[] args args public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	} rolling {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	} if (arr.length < 2)
			return; arr.length < 2 arr.length arr arr.length 2 return; for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1]; int i = 1; int i = 1; i 1 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] += arr[i - 1]; arr[i] += arr[i - 1] arr[i] arr i arr[i - 1] arr i - 1 i 1 int[] arr arr public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	} rolling {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	} if (arr.length < 2)
			return; arr.length < 2 arr.length arr arr.length 2 return; for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1]; int i = 1; int i = 1; i 1 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] += arr[i - 1]; arr[i] += arr[i - 1] arr[i] arr i arr[i - 1] arr i - 1 i 1 long[] arr arr public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	} reverse {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	} for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		} int i = 0; int i = 0; i 0 i < arr.length / 2 i arr.length / 2 arr.length arr arr.length 2 i++ i++ i {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		} {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		} int temp = arr[i]; temp arr[i] arr i arr[i] = arr[arr.length - 1 - i] arr[i] arr i arr[arr.length - 1 - i] arr arr.length - 1 - i arr.length - 1 - i arr.length arr arr.length 1 i arr[arr.length - 1 - i] = temp arr[arr.length - 1 - i] arr arr.length - 1 - i arr.length - 1 - i arr.length arr arr.length 1 i temp int[] arr arr public static void print(String s) {
		System.out.println(s);
	} print {
		System.out.println(s);
	} System.out.println(s) System.out.println System.out System System.out s String s s public static void print(long s) {
		System.out.println(s);
	} print {
		System.out.println(s);
	} System.out.println(s) System.out.println System.out System System.out s long s s public static void print(int s) {
		System.out.println(s);
	} print {
		System.out.println(s);
	} System.out.println(s) System.out.println System.out System System.out s int s s static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	} FastReader BufferedReader br; br StringTokenizer st; st public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		} FastReader {
			br = new BufferedReader(new InputStreamReader(System.in));
		} br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) int ri() {
			return Integer.parseInt(str());
		} ri {
			return Integer.parseInt(str());
		} return Integer.parseInt(str()); Integer.parseInt(str()) Integer.parseInt Integer str() str long rl() {
			return Long.parseLong(str());
		} rl {
			return Long.parseLong(str());
		} return Long.parseLong(str()); Long.parseLong(str()) Long.parseLong Long str() str double rd() {
			return Double.parseDouble(str());
		} rd {
			return Double.parseDouble(str());
		} return Double.parseDouble(str()); Double.parseDouble(str()) Double.parseDouble Double str() str String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		} str {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		} String str = ""; str "" try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} IOException e {
				e.printStackTrace();
			} e.printStackTrace() e.printStackTrace e {
				str = br.readLine();
			} str = br.readLine() str br.readLine() br.readLine br return str; str String[] rsa() {
			return str().split(" ");
		} rsa {
			return str().split(" ");
		} return str().split(" "); str().split(" ") str().split str() str " " int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		} ria {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		} String[] s = rsa(); s rsa() rsa int[] arr = new int[s.length]; arr new int[s.length] s.length s s.length for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]); int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = Integer.parseInt(s[i]); arr[i] = Integer.parseInt(s[i]) arr[i] arr i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i return arr; arr long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		} rla {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		} String[] s = rsa(); s rsa() rsa long[] arr = new long[s.length]; arr new long[s.length] s.length s s.length for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]); int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = Long.parseLong(s[i]); arr[i] = Long.parseLong(s[i]) arr[i] arr i Long.parseLong(s[i]) Long.parseLong Long s[i] s i return arr; arr char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		} rca {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		} String s = str(); s str() str char[] arr = new char[s.length()]; arr new char[s.length()] s.length() s.length s for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i); int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = s.charAt(i); arr[i] = s.charAt(i) arr[i] arr i s.charAt(i) s.charAt s i return arr; arr String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		} rsaml {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		} String[] arr = new String[m]; arr new String[m] m for (int i = 0; i < arr.length; i++)
				arr[i] = str(); int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = str(); arr[i] = str() arr[i] arr i str() str return arr; arr int m m int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		} riaml {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		} int[] arr = new int[m]; arr new int[m] m for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str()); int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = Integer.parseInt(str()); arr[i] = Integer.parseInt(str()) arr[i] arr i Integer.parseInt(str()) Integer.parseInt Integer str() str return arr; arr int m m long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		} rlaml {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		} long[] arr = new long[m]; arr new long[m] m for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str()); int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = Long.parseLong(str()); arr[i] = Long.parseLong(str()) arr[i] arr i Long.parseLong(str()) Long.parseLong Long str() str return arr; arr int m m class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
} Node public int val; val public boolean visited; visited public Node(int v) { val=v; } Node { val=v; } val=v val v int v v public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
} public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
} Main

import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		Map<String,String> map = new HashMap<>();
		map.put("a", r.str());
		map.put("b", r.str());
		map.put("c", r.str());
		String next = "a";
		int Apos = 0;
		int Bpos = 0;
		int Cpos = 0;
		while(true) {
			if(next.equals("a"))
			{
				if(map.get(next).length() == Apos) {
					print("A");
					return;
				}
				next = ""+map.get(next).charAt(Apos++);				
			}
			if(next.equals("b"))
			{
				if(map.get(next).length() == Bpos) {
					print("B");
					return;
				}
				next = ""+map.get(next).charAt(Bpos++);				
			}
			if(next.equals("c"))
			{
				if(map.get(next).length() == Cpos) {
					print("C");
					return;
				}
				next = ""+map.get(next).charAt(Cpos++);				
			}
		}
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}