import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
} import java.util.*; util.* java import java.io.*; io.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc String result = ""; result "" int ia = 0; ia 0 int ib = 0; ib 0 int ic = 0; ic 0 char next = 'a'; next 'a' while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		} true {
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		} if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    } next == 'a' next 'a' {
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    } if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        } ia == a.length() ia a.length() a.length a {
		            result = "A";
		            break;
		        } result = "A" result "A" break; {
		            next = a.charAt(ia);
		            ia++;
		        } next = a.charAt(ia) next a.charAt(ia) a.charAt a ia ia++ ia if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    } next == 'b' next 'b' {
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    } if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        } ib == b.length() ib b.length() b.length b {
		            result = "B";
		            break;
		        } result = "B" result "B" break; {
		            next = b.charAt(ib);
		            ib++;
		        } next = b.charAt(ib) next b.charAt(ib) b.charAt b ib ib++ ib {
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    } if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        } ic == c.length() ic c.length() c.length c {
		            result = "C";
		            break;
		        } result = "C" result "C" break; {
		            next = c.charAt(ic);
		            ic++;
		        } next = c.charAt(ic) next c.charAt(ic) c.charAt c ic ic++ ic System.out.println(result) System.out.println System.out System System.out result String[] args args public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	} Scanner private BufferedReader br; br private StringTokenizer tok; tok public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));} Scanner { br = new BufferedReader(new InputStreamReader(is));} br = new BufferedReader(new InputStreamReader(is)) br new BufferedReader(new InputStreamReader(is)) InputStream is is private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());} getLine { while(!hasNext()) tok = new StringTokenizer(br.readLine());} while(!hasNext()) tok = new StringTokenizer(br.readLine()); !hasNext() hasNext() hasNext tok = new StringTokenizer(br.readLine()) tok new StringTokenizer(br.readLine()) private boolean hasNext() { return tok != null && tok.hasMoreTokens();} hasNext { return tok != null && tok.hasMoreTokens();} return tok != null && tok.hasMoreTokens(); tok != null && tok.hasMoreTokens() tok != null tok null tok.hasMoreTokens() tok.hasMoreTokens tok public String next() throws IOException { getLine(); return tok.nextToken();} next { getLine(); return tok.nextToken();} getLine() getLine return tok.nextToken(); tok.nextToken() tok.nextToken tok public int nextInt() throws IOException { return Integer.parseInt(next());} nextInt { return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() throws IOException { return Long.parseLong(next());} nextLong { return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() throws IOException { return Double.parseDouble(next());} nextDouble { return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
} public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
} Main
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		// 計算
		String result = "";
		int ia = 0;
		int ib = 0;
		int ic = 0;
		char next = 'a';
		while(true){
		    if(next == 'a'){
		        if(ia == a.length()){
		            result = "A";
		            break;
		        }else{
		            next = a.charAt(ia);
		            ia++;
		        }
		    }else if(next == 'b'){
		        if(ib == b.length()){
		            result = "B";
		            break;
		        }else{
		            next = b.charAt(ib);
		            ib++;
		        }
		    }else{
		        if(ic == c.length()){
		            result = "C";
		            break;
		        }else{
		            next = c.charAt(ic);
		            ic++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}
