import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	} main {
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] tA=sc.nextLine().split(""); tA sc.nextLine().split("") sc.nextLine().split sc.nextLine() sc.nextLine sc "" String[] tB=sc.nextLine().split(""); tB sc.nextLine().split("") sc.nextLine().split sc.nextLine() sc.nextLine sc "" String[] tC=sc.nextLine().split(""); tC sc.nextLine().split("") sc.nextLine().split sc.nextLine() sc.nextLine sc "" Queue<String> qA = new ArrayDeque<>(); qA new ArrayDeque<>() Queue<String> qB = new ArrayDeque<>(); qB new ArrayDeque<>() Queue<String> qC = new ArrayDeque<>(); qC new ArrayDeque<>() for(String tem:tA)qA.add(tem); String tem tA qA.add(tem); qA.add(tem) qA.add qA tem for(String tem:tB)qB.add(tem); String tem tB qB.add(tem); qB.add(tem) qB.add qB tem for(String tem:tC)qC.add(tem); String tem tC qC.add(tem); qC.add(tem) qC.add qC tem String beg=qA.poll(); beg qA.poll() qA.poll qA while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

} true {
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

} String pre=beg; pre beg switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
} beg case "a": "a" case "a": beg=qA.poll() beg qA.poll() qA.poll qA break; case "b": "b" case "b": beg=qB.poll() beg qB.poll() qB.poll qB break; case "c": "c" case "c": beg=qC.poll() beg qC.poll() qC.poll qC break; if(beg==null){
System.out.println(pre.toUpperCase());
break;
} beg==null beg null {
System.out.println(pre.toUpperCase());
break;
} System.out.println(pre.toUpperCase()) System.out.println System.out System System.out pre.toUpperCase() pre.toUpperCase pre break; String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	}
} Main
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] tA=sc.nextLine().split("");
      String[] tB=sc.nextLine().split("");
      String[] tC=sc.nextLine().split("");

//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

//int A=Integer.parseInt(t[0]);
//int B=Integer.parseInt(t[1]);

Queue<String> qA = new ArrayDeque<>();
Queue<String> qB = new ArrayDeque<>();
Queue<String> qC = new ArrayDeque<>();

for(String tem:tA)qA.add(tem);
for(String tem:tB)qB.add(tem);
for(String tem:tC)qC.add(tem);

String beg=qA.poll();

while(true){
String pre=beg;

//System.out.println(beg+"--");
switch(beg){
case "a":
beg=qA.poll();
break;
case "b":
beg=qB.poll();
break;
case "c":
beg=qC.poll();
break;
}

if(beg==null){
System.out.println(pre.toUpperCase());
break;
}

}




	}
}