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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

} Main public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	} main {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	} BufferedReader input =new BufferedReader (new InputStreamReader (System.in)); input new BufferedReader (new InputStreamReader (System.in)) String stra = input.readLine( ); stra input.readLine( ) input.readLine input String strb = input.readLine( ); strb input.readLine( ) input.readLine input String strc = input.readLine( ); strc input.readLine( ) input.readLine input String[] list  = new String[3]; list new String[3] 3 list[0] = stra list[0] list 0 stra list[1] = strb list[1] list 1 strb list[2] = strc list[2] list 2 strc int next = 0; next 0 String answer = ""; answer "" while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		} list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0 list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0 list[0].length() >= 0 list[0].length() list[0].length list[0] list 0 0 list[1].length() >= 0 list[1].length() list[1].length list[1] list 1 0 list[2].length() >= 0 list[2].length() list[2].length list[2] list 2 0 {
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		} if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			} list[next].length() == 0 list[next].length() list[next].length list[next] list next 0 {
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			} if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				} next == 0 next 0 {
					answer = "A";
				} answer = "A" answer "A" if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				} next == 1 next 1 {
					answer = "B";
				} answer = "B" answer "B" if(next == 2){
					answer = "C";
				} next == 2 next 2 {
					answer = "C";
				} answer = "C" answer "C" System.out.println(answer) System.out.println System.out System System.out answer break; if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			} list[next].startsWith("a") list[next].startsWith list[next] list next "a" {
				list[next] = list[next].substring(1);
				next = 0;
			} list[next] = list[next].substring(1) list[next] list next list[next].substring(1) list[next].substring list[next] list next 1 next = 0 next 0 if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			} list[next].startsWith("b") list[next].startsWith list[next] list next "b" {
				list[next] = list[next].substring(1);
				next = 1;
			} list[next] = list[next].substring(1) list[next] list next list[next].substring(1) list[next].substring list[next] list next 1 next = 1 next 1 if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			} list[next].startsWith("c") list[next].startsWith list[next] list next "c" {
				list[next] = list[next].substring(1);
				next = 2;
			} list[next] = list[next].substring(1) list[next] list next list[next].substring(1) list[next].substring list[next] list next 1 next = 2 next 2 String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

}
