import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}
 import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.NoSuchElementException; NoSuchElementException java.util public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
} Main //FastScanner
	static InputStream in = System.in; in System.in System System.in static  byte[] buffer = new byte[1024]; buffer new byte[1024] 1024 static int length = 0 length 0 p = 0; p 0 public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	} main {
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	} PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) String S[]=new String[3]; S new String[3] 3 int s[]=new int[3]; s new int[3] 3 for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();} int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {S[i]=next();s[i]=S[i].length();} {S[i]=next();s[i]=S[i].length();} S[i]=next() S[i] S i next() next s[i]=S[i].length() s[i] s i S[i].length() S[i].length S[i] S i int now=0; now 0 while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		} true {
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		} if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			} s[now]==0 s[now] s now 0 {
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			} switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				} now case 0: 0 case 0: System.out.println("A") System.out.println System.out System System.out "A" break; case 1: 1 case 1: System.out.println("B") System.out.println System.out System System.out "B" break; case 2: 2 case 2: System.out.println("C") System.out.println System.out System System.out "C" break; System.exit(0) System.exit System 0 s[now]-- s[now] s now char a=S[now].charAt(0); a S[now].charAt(0) S[now].charAt S[now] S now 0 S[now]=S[now].substring(1,S[now].length()) S[now] S now S[now].substring(1,S[now].length()) S[now].substring S[now] S now 1 S[now].length() S[now].length S[now] S now switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			} a case 'a': 'a' case 'a': now=0 now 0 break; case 'b': 'b' case 'b': now=1 now 1 break; case 'c': 'c' case 'c': now=2 now 2 break; String[] args args static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	} isOK {
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	} if (a[index].compareTo(key)>=0) return true;
	    else return false; a[index].compareTo(key)>=0 a[index].compareTo(key) a[index].compareTo a[index] a index key 0 return true; true return false; false int index index String key key String[]a a static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	} binary_search {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	} int ng = -1; ng -1 1 int ok = (int)a.length; ok (int)a.length a a.length while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    } Math.abs(ok - ng) > 1 Math.abs(ok - ng) Math.abs Math ok - ng ok ng 1 {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    } int mid = (ok + ng) / 2; mid (ok + ng) / 2 (ok + ng) ok ng 2 if (isOK(mid,key,a)) ok = mid;
	        else ng = mid; isOK(mid,key,a) isOK mid key a ok = mid ok mid ng = mid ng mid return ok; ok String key key String[] a a public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	} hasNextByte {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	} if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		} p < length p length return true; true {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		} p = 0 p 0 try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {length = in.read(buffer);} length = in.read(buffer) length in.read(buffer) in.read in buffer if (length == 0) return false; length == 0 length 0 return false; false return true; true public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	} readByte {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	} if (hasNextByte() == true) return buffer[p++]; hasNextByte() == true hasNextByte() hasNextByte true return buffer[p++]; buffer[p++] buffer p++ p return -1; -1 1 public static boolean isPrintable (int n) {return 33<=n&&n<=126;} isPrintable {return 33<=n&&n<=126;} return 33<=n&&n<=126; 33<=n&&n<=126 33<=n 33 n n<=126 n 126 int n n public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	} skip {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	} while (hasNextByte() && !isPrintable(buffer[p])) p++; hasNextByte() && !isPrintable(buffer[p]) hasNextByte() hasNextByte !isPrintable(buffer[p]) isPrintable(buffer[p]) isPrintable buffer[p] buffer p p++ p public static boolean hasNext () {skip(); return hasNextByte();} hasNext {skip(); return hasNextByte();} skip() skip return hasNextByte(); hasNextByte() hasNextByte public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	} next {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	} if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int temp = readByte(); temp readByte() readByte while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		} isPrintable(temp) isPrintable temp {
			sb.appendCodePoint(temp);
			temp = readByte();
		} sb.appendCodePoint(temp) sb.appendCodePoint sb temp temp = readByte() temp readByte() readByte return sb.toString(); sb.toString() sb.toString sb public static int nextInt () {return Math.toIntExact(nextLong());} nextInt {return Math.toIntExact(nextLong());} return Math.toIntExact(nextLong()); Math.toIntExact(nextLong()) Math.toIntExact Math nextLong() nextLong public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	} nextInts {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	} int[] ar = new int[n]; ar new int[n] n for (int i=0; i<n; i++) ar[i] = nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i ar[i] = nextInt(); ar[i] = nextInt() ar[i] ar i nextInt() nextInt return ar; ar int n n public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	} nextLong {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	} if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() boolean minus = false; minus false int temp = readByte(); temp readByte() readByte if (temp == '-') {
			minus = true;
			temp = readByte();
		} temp == '-' temp '-' {
			minus = true;
			temp = readByte();
		} minus = true minus true temp = readByte() temp readByte() readByte if (temp<'0' || '9'<temp) throw new NumberFormatException(); temp<'0' || '9'<temp temp<'0' temp '0' '9'<temp '9' temp throw new NumberFormatException(); new NumberFormatException() long n = 0; n 0 while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		} isPrintable(temp) isPrintable temp {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		} if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			} '0'<=temp && temp<='9' '0'<=temp '0' temp temp<='9' temp '9' {
				n *= 10;
				n += temp - '0';
			} n *= 10 n 10 n += temp - '0' n temp - '0' temp '0' temp = readByte() temp readByte() readByte return minus? -n : n; minus? -n : n minus -n n n public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
} public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
} Main
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}

