import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


} import java.io.*; io.* java import java.util.*; util.* java public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


} Main final static long MOD = 1000000007L; MOD 1000000007L public static String[] Ws = null; Ws null public static int wsIndx = 0; wsIndx 0 public static BufferedReader in = null; in null public static ArrayList<int[]> list = new ArrayList<>(); list new ArrayList<>() public static void main(String[] args) throws Exception {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	} main {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	} String[] a = toStringArray(nextString()); a toStringArray(nextString()) toStringArray nextString() nextString String[] b = toStringArray(nextString()); b toStringArray(nextString()) toStringArray nextString() nextString String[] c = toStringArray(nextString()); c toStringArray(nextString()) toStringArray nextString() nextString int ai=0; ai 0 int bi=0; bi 0 int ci=0; ci 0 String next="a"; next "a" String ans =""; ans "" while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		} ai<=a.length&&bi<=b.length&&ci<=c.length ai<=a.length&&bi<=b.length&&ci<=c.length ai<=a.length ai a.length a a.length bi<=b.length bi b.length b b.length ci<=c.length ci c.length c c.length {
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		} if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			} "a".equals(next) "a".equals "a" next {
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			} if(ai==a.length){
					ans="A";
					break;
				} ai==a.length ai a.length a a.length {
					ans="A";
					break;
				} ans="A" ans "A" break; next=a[ai] next a[ai] a ai ai++ ai if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			} "b".equals(next) "b".equals "b" next {
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			} if(bi==b.length){
					ans="B";
					break;
				} bi==b.length bi b.length b b.length {
					ans="B";
					break;
				} ans="B" ans "B" break; next=b[bi] next b[bi] b bi bi++ bi {
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			} if(ci==c.length){
					ans="C";
					break;
				} ci==c.length ci c.length c c.length {
					ans="C";
					break;
				} ans="C" ans "C" break; next=c[ci] next c[ci] c ci ci++ ci System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
} gcd {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
} long x x y; y if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	} a < b a b {
		x = b;
		y = a;
	} x = b x b y = a y a {
		x = a;
		y = b;
	} x = a x a y = b y b long r; r while ((r = a % b) != 0) {
		a = b;
		b = r;
	} (r = a % b) != 0 (r = a % b) r a % b a b 0 {
		a = b;
		b = r;
	} a = b a b b = r b r return b; b long a a long b b public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
} lcm {
	long x, y;

	return ((a/gcd(a,b))*b);
} long x x y; y return ((a/gcd(a,b))*b); ((a/gcd(a,b))*b) (a/gcd(a,b)) a gcd(a,b) gcd a b b long a a long b b public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	} toStringArray {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	} String[] tmp = new String[s.length()]; tmp new String[s.length()] s.length() s.length s char[] c = s.toCharArray(); c s.toCharArray() s.toCharArray s for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		} int i = 0; int i = 0; i 0 i < tmp.length i tmp.length tmp tmp.length i++ i++ i {
			tmp[i] = String.valueOf(c[i]);
		} {
			tmp[i] = String.valueOf(c[i]);
		} tmp[i] = String.valueOf(c[i]) tmp[i] tmp i String.valueOf(c[i]) String.valueOf String c[i] c i return tmp; tmp String s s public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	} concatStringArray {
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	} StringBuffer sb = new StringBuffer(); sb new StringBuffer() for(String x:s){
			sb.append(x);
		} String x s {
			sb.append(x);
		} {
			sb.append(x);
		} sb.append(x) sb.append sb x return sb.toString(); sb.toString() sb.toString sb String[] s s public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	} check {
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	} if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		} in == null in null {
			in = new BufferedReader(new InputStreamReader(System.in));
		} in = new BufferedReader(new InputStreamReader(System.in)) in new BufferedReader(new InputStreamReader(System.in)) if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		} Ws==null || Ws.length<=wsIndx Ws==null Ws null Ws.length<=wsIndx Ws.length Ws Ws.length wsIndx {
			Ws = in.readLine().split(" ");
			wsIndx=0;
		} Ws = in.readLine().split(" ") Ws in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " wsIndx=0 wsIndx 0 public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	} nextInt {
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	} check() check return Integer.parseInt(Ws[wsIndx++]); Integer.parseInt(Ws[wsIndx++]) Integer.parseInt Integer Ws[wsIndx++] Ws wsIndx++ wsIndx public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	} nextLong {
		check();
		return Long.parseLong(Ws[wsIndx++]);
	} check() check return Long.parseLong(Ws[wsIndx++]); Long.parseLong(Ws[wsIndx++]) Long.parseLong Long Ws[wsIndx++] Ws wsIndx++ wsIndx public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	} nextString {
		check();
		return Ws[wsIndx++];
	} check() check return Ws[wsIndx++]; Ws[wsIndx++] Ws wsIndx++ wsIndx public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	} nextInts {
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	} check() check int[] tmp = new int[Ws.length]; tmp new int[Ws.length] Ws.length Ws Ws.length for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		} int i=0; int i=0; i 0 i<tmp.length i tmp.length tmp tmp.length i++ i++ i {
			tmp[i]=Integer.parseInt(Ws[i]);
		} {
			tmp[i]=Integer.parseInt(Ws[i]);
		} tmp[i]=Integer.parseInt(Ws[i]) tmp[i] tmp i Integer.parseInt(Ws[i]) Integer.parseInt Integer Ws[i] Ws i wsIndx=Ws.length wsIndx Ws.length Ws Ws.length return tmp; tmp public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	} nextLongs {
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	} check() check long[] tmp = new long[Ws.length]; tmp new long[Ws.length] Ws.length Ws Ws.length for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		} int i=0; int i=0; i 0 i<tmp.length i tmp.length tmp tmp.length i++ i++ i {
			tmp[i]=Long.parseLong(Ws[i]);
		} {
			tmp[i]=Long.parseLong(Ws[i]);
		} tmp[i]=Long.parseLong(Ws[i]) tmp[i] tmp i Long.parseLong(Ws[i]) Long.parseLong Long Ws[i] Ws i wsIndx=Ws.length wsIndx Ws.length Ws Ws.length return tmp; tmp public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	} nextStrings {
		check();
		wsIndx=Ws.length;
		return Ws;
	} check() check wsIndx=Ws.length wsIndx Ws.length Ws Ws.length return Ws; Ws public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


} public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


} Main
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String[] a = toStringArray(nextString());
		String[] b = toStringArray(nextString());
		String[] c = toStringArray(nextString());
		int ai=0;
		int bi=0;
		int ci=0;
		String next="a";
		String ans ="";
		while(ai<=a.length&&bi<=b.length&&ci<=c.length){
			if("a".equals(next)){
				if(ai==a.length){
					ans="A";
					break;
				}
				next=a[ai];
				ai++;
			}else if("b".equals(next)){
				if(bi==b.length){
					ans="B";
					break;
				}
				next=b[bi];
				bi++;

			}else{
				if(ci==c.length){
					ans="C";
					break;
				}
				next=c[ci];
				ci++;

			}
		}
		System.out.println(ans);

	}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

public static long lcm(long a, long b) {
	long x, y;

	return ((a/gcd(a,b))*b);
}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}