import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
} import java.io.*; io.* java import java.math.*; math.* java import java.util.*; util.* java public class Main {  
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
} Main public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	} main {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	} FastScanner I = new FastScanner(); I new FastScanner() OutPut O = new OutPut(); O new OutPut() String a = I.next().toUpperCase(); a I.next().toUpperCase() I.next().toUpperCase I.next() I.next I String b = I.next().toUpperCase(); b I.next().toUpperCase() I.next().toUpperCase I.next() I.next I String c = I.next().toUpperCase(); c I.next().toUpperCase() I.next().toUpperCase I.next() I.next I Queue<Character> A = new LinkedList<Character>(); A new LinkedList<Character>() Queue<Character> B = new LinkedList<Character>(); B new LinkedList<Character>() Queue<Character> C = new LinkedList<Character>(); C new LinkedList<Character>() char cur = 'A'; cur 'A' String ans = ""; ans "" for (int i = 0; i < a.length(); i++) A.add(a.charAt(i)); int i = 0; int i = 0; i 0 i < a.length() i a.length() a.length a i++ i++ i A.add(a.charAt(i)); A.add(a.charAt(i)) A.add A a.charAt(i) a.charAt a i for (int i = 0; i < b.length(); i++) B.add(b.charAt(i)); int i = 0; int i = 0; i 0 i < b.length() i b.length() b.length b i++ i++ i B.add(b.charAt(i)); B.add(b.charAt(i)) B.add B b.charAt(i) b.charAt b i for (int i = 0; i < c.length(); i++) C.add(c.charAt(i)); int i = 0; int i = 0; i 0 i < c.length() i c.length() c.length c i++ i++ i C.add(c.charAt(i)); C.add(c.charAt(i)) C.add C c.charAt(i) c.charAt c i while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		} true {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		} if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			} cur=='A' cur 'A' {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			} if (A.size()==0) {
					ans="A";
					break;
				} A.size()==0 A.size() A.size A 0 {
					ans="A";
					break;
				} ans="A" ans "A" break; cur=A.poll() cur A.poll() A.poll A if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			} cur=='B' cur 'B' {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			} if (B.size()==0) {
					ans="B";
					break;
				} B.size()==0 B.size() B.size B 0 {
					ans="B";
					break;
				} ans="B" ans "B" break; cur=B.poll() cur B.poll() B.poll B {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			} if (C.size()==0) {
					ans="C";
					break;
				} C.size()==0 C.size() C.size C 0 {
					ans="C";
					break;
				} ans="C" ans "C" break; cur=C.poll() cur C.poll() C.poll C O.pln(ans) O.pln O ans String[] args args public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;} ceil {long ans = num/den; if (num%den!=0) 
	ans++; return ans;} long ans = num/den; ans num/den num den if (num%den!=0) 
	ans++; num%den!=0 num%den num den 0 ans++ ans return ans; ans long num num long den den public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	} GCD {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	} if (a==0||b==0) return Math.max(a,b); a==0||b==0 a==0 a 0 b==0 b 0 return Math.max(a,b); Math.max(a,b) Math.max Math a b return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b)); GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b)) GCD Math.min(a, b) Math.min Math a b Math.max(a, b)%Math.min(a, b) Math.max(a, b) Math.max Math a b Math.min(a, b) Math.min Math a b long a a long b b public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	} FastExp {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	} long ans=1; ans 1 while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		} exp>0 exp 0 {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		} if (exp%2==1) ans*=base; exp%2==1 exp%2 exp 2 1 ans*=base ans base exp/=2 exp 2 base*=base base base base%=mod base mod ans%=mod ans mod return ans; ans long base base long exp exp long mod mod public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);} ModInv {return FastExp(num,mod-2,mod);} return FastExp(num,mod-2,mod); FastExp(num,mod-2,mod) FastExp num mod-2 mod 2 mod long num num long mod mod public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	} pop { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	} int cnt = 0; cnt 0 while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		} x>0 x 0 {
			if (x%2==1) cnt++;
			x/=2;
		} if (x%2==1) cnt++; x%2==1 x%2 x 2 1 cnt++ cnt x/=2 x 2 return cnt; cnt long x x static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	} FastScanner BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st=new StringTokenizer(""); st new StringTokenizer("") String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		} next {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		} while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				} !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} IOException e {
					e.printStackTrace();
				} e.printStackTrace() e.printStackTrace e {
					st=new StringTokenizer(br.readLine());
				} st=new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {return Integer.parseInt(next());} nextInt {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {return Long.parseLong(next());} nextLong {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	} OutPut PrintWriter w = new PrintWriter(System.out); w new PrintWriter(System.out) void pln(double x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w double x x void pln(boolean x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w boolean x x void pln(int x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w int x x void pln(long x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w long x x void pln(String x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w String x x void pln(char x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w char x x void pln(StringBuilder x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w StringBuilder x x void pln(BigInteger x) {w.println(x);w.flush();} pln {w.println(x);w.flush();} w.println(x) w.println w x w.flush() w.flush w BigInteger x x void p(int x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w int x x void p(long x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w long x x void p(String x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w String x x void p(char x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w char x x void p(StringBuilder x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w StringBuilder x x void p(BigInteger x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w BigInteger x x void p(double x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w double x x void p(boolean x) {w.print(x);w.flush();} p {w.print(x);w.flush();} w.print(x) w.print w x w.flush() w.flush w boolean x x public class Main {  
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
} public class Main {  
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
} Main
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}