import java.util.*;

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

Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String c = sc.next();

int win = 0;

String field = a.substring(0,1);
a = a.substring(1);

for(;;){
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
}
if(win == 1){
System.out.println("A");
}else if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
}

}
} import java.util.*; util.* java class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String c = sc.next();

int win = 0;

String field = a.substring(0,1);
a = a.substring(1);

for(;;){
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
}
if(win == 1){
System.out.println("A");
}else if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
}

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

Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String c = sc.next();

int win = 0;

String field = a.substring(0,1);
a = a.substring(1);

for(;;){
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
}
if(win == 1){
System.out.println("A");
}else if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
}

} main {

Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String c = sc.next();

int win = 0;

String field = a.substring(0,1);
a = a.substring(1);

for(;;){
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
}
if(win == 1){
System.out.println("A");
}else if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
}

} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc int win = 0; win 0 String field = a.substring(0,1); field a.substring(0,1) a.substring a 0 1 a = a.substring(1) a a.substring(1) a.substring a 1 for(;;){
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
} ; {
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
} {
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
} if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
} field.equals("a") field.equals field "a" {
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
} if(a.equals("")){
win = 1;
break;
} a.equals("") a.equals a "" {
win = 1;
break;
} win = 1 win 1 break; field = a.substring(0,1) field a.substring(0,1) a.substring a 0 1 a = a.substring(1) a a.substring(1) a.substring a 1 if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
} field.equals("b") field.equals field "b" {
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
} if(b.equals("")){
win = 2;
break;
} b.equals("") b.equals b "" {
win = 2;
break;
} win = 2 win 2 break; field = b.substring(0,1) field b.substring(0,1) b.substring b 0 1 b = b.substring(1) b b.substring(1) b.substring b 1 {
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
} if(c.equals("")){
win = 3;
break;
} c.equals("") c.equals c "" {
win = 3;
break;
} win = 3 win 3 break; field = c.substring(0,1) field c.substring(0,1) c.substring c 0 1 c = c.substring(1) c c.substring(1) c.substring c 1 if(win == 1){
System.out.println("A");
}else if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
} win == 1 win 1 {
System.out.println("A");
} System.out.println("A") System.out.println System.out System System.out "A" if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
} win == 2 win 2 {
System.out.println("B");
} System.out.println("B") System.out.println System.out System System.out "B" {
System.out.println("C");
} System.out.println("C") System.out.println System.out System System.out "C" String[] args args
import java.util.*;

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

Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String c = sc.next();

int win = 0;

String field = a.substring(0,1);
a = a.substring(1);

for(;;){
if(field.equals("a")){
if(a.equals("")){
win = 1;
break;
}
field = a.substring(0,1);
a = a.substring(1);
}else if(field.equals("b")){
if(b.equals("")){
win = 2;
break;
}
field = b.substring(0,1);
b = b.substring(1);
}else{
if(c.equals("")){
win = 3;
break;
}
field = c.substring(0,1);
c = c.substring(1);
}
}
if(win == 1){
System.out.println("A");
}else if(win == 2){
System.out.println("B");
}else{
System.out.println("C");
}

}
}