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

public class Main {
	public static void main(String[] args) {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		}
	}


class Input{

	private String buf;
	BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(System.in));
	
    public String input() {
	try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
	}
	return buf;
	}
}


class Converter{

	private int convInt=0;
	private String convStrArr[];

	public int int_(String convInt){
		this.convInt = Integer.parseInt(convInt);
		return this.convInt;
	}

	public String[] strArr_(String convStrArr,String breakStr){
		this.convStrArr = convStrArr.split(breakStr,0);
		return this.convStrArr;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		}
	} Main public static void main(String[] args) {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		} main {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		} Input input = new Input(); input new Input() Converter conv = new Converter(); conv new Converter() String a[]= conv.strArr_(input.input(), ""); a conv.strArr_(input.input(), "") conv.strArr_ conv input.input() input.input input "" String b[] = conv.strArr_(input.input(), ""); b conv.strArr_(input.input(), "") conv.strArr_ conv input.input() input.input input "" String c[] = conv.strArr_(input.input(), ""); c conv.strArr_(input.input(), "") conv.strArr_ conv input.input() input.input input "" int asize = a.length asize a.length a a.length bsize = b.length bsize b.length b b.length csize = c.length; csize c.length c c.length int acount=0 acount 0 bcount=0 bcount 0 ccount=0; ccount 0 String index = a[0]; index a[0] a 0 acount++ acount while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		} acount<=asize && bcount<=bsize && ccount<=csize acount<=asize && bcount<=bsize && ccount<=csize acount<=asize acount asize bcount<=bsize bcount bsize ccount<=csize ccount csize {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		} switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			} index case "a": "a" case "a": if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					} acount == asize acount asize {
					System.out.println("A");
					acount++;
				} System.out.println("A") System.out.println System.out System System.out "A" acount++ acount {
					index = a[acount];
					acount++;
					} index = a[acount] index a[acount] a acount acount++ acount break; case "b": "b" case "b": if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					} bcount == bsize bcount bsize {
					System.out.println("B");
					bcount++;
				} System.out.println("B") System.out.println System.out System System.out "B" bcount++ bcount {
					index = b[bcount];
					bcount++;
					} index = b[bcount] index b[bcount] b bcount bcount++ bcount break; case "c": "c" case "c": if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					} ccount == csize ccount csize {
					System.out.println("C");
					ccount++;
				} System.out.println("C") System.out.println System.out System System.out "C" ccount++ ccount {
					index = c[ccount];
					ccount++;
					} index = c[ccount] index c[ccount] c ccount ccount++ ccount break; String[] args args class Input{

	private String buf;
	BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(System.in));
	
    public String input() {
	try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
	}
	return buf;
	}
} Input private String buf; buf BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(System.in)); bufferdReader new BufferedReader(new InputStreamReader(System.in)) public String input() {
	try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
	}
	return buf;
	} input {
	try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
	}
	return buf;
	} try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
	} catch(Exception e) {
	} Exception e {
	} {
		this.buf = bufferdReader.readLine();
	} this.buf = bufferdReader.readLine() this.buf this this.buf bufferdReader.readLine() bufferdReader.readLine bufferdReader return buf; buf class Converter{

	private int convInt=0;
	private String convStrArr[];

	public int int_(String convInt){
		this.convInt = Integer.parseInt(convInt);
		return this.convInt;
	}

	public String[] strArr_(String convStrArr,String breakStr){
		this.convStrArr = convStrArr.split(breakStr,0);
		return this.convStrArr;
	}
} Converter private int convInt=0; convInt 0 private String convStrArr[]; convStrArr public int int_(String convInt){
		this.convInt = Integer.parseInt(convInt);
		return this.convInt;
	} int_ {
		this.convInt = Integer.parseInt(convInt);
		return this.convInt;
	} this.convInt = Integer.parseInt(convInt) this.convInt this this.convInt Integer.parseInt(convInt) Integer.parseInt Integer convInt return this.convInt; this.convInt this this.convInt String convInt convInt public String[] strArr_(String convStrArr,String breakStr){
		this.convStrArr = convStrArr.split(breakStr,0);
		return this.convStrArr;
	} strArr_ {
		this.convStrArr = convStrArr.split(breakStr,0);
		return this.convStrArr;
	} this.convStrArr = convStrArr.split(breakStr,0) this.convStrArr this this.convStrArr convStrArr.split(breakStr,0) convStrArr.split convStrArr breakStr 0 return this.convStrArr; this.convStrArr this this.convStrArr String convStrArr convStrArr String breakStr breakStr public class Main {
	public static void main(String[] args) {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		}
	} public class Main {
	public static void main(String[] args) {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		}
	} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {

		Input input = new Input();
		Converter conv = new Converter();
		String a[]= conv.strArr_(input.input(), "");
		String b[] = conv.strArr_(input.input(), "");
		String c[] = conv.strArr_(input.input(), "");
		int asize = a.length,bsize = b.length,csize = c.length;
		int acount=0,bcount=0,ccount=0;

		String index = a[0];
		acount++ ;

		while(acount<=asize && bcount<=bsize && ccount<=csize) {
			switch(index) {
			case "a":
				if(acount == asize) {
					System.out.println("A");
					acount++;
				}else{
					index = a[acount];
					acount++;
					}
				break;

			case "b":
				if(bcount == bsize) {
					System.out.println("B");
					bcount++;
				}else{
					index = b[bcount];
					bcount++;
					}
				break;

			case "c":
				if(ccount == csize) {
					System.out.println("C");
					ccount++;
				}else{
					index = c[ccount];
					ccount++;
					}
				break;
			}
		}
		}
	}


class Input{

	private String buf;
	BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(System.in));
	
    public String input() {
	try{
		this.buf = bufferdReader.readLine();
	}catch(Exception e) {
	}
	return buf;
	}
}


class Converter{

	private int convInt=0;
	private String convStrArr[];

	public int int_(String convInt){
		this.convInt = Integer.parseInt(convInt);
		return this.convInt;
	}

	public String[] strArr_(String convStrArr,String breakStr){
		this.convStrArr = convStrArr.split(breakStr,0);
		return this.convStrArr;
	}
}
