import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	} main {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String a = scan.next(); a scan.next() scan.next scan String b = scan.next(); b scan.next() scan.next scan String c = scan.next(); c scan.next() scan.next scan scan.close() scan.close scan int cnt[]= {0,0,0}; cnt {0,0,0} 0 0 0 int next=0; next 0 char fin='f'; fin 'f' while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		} true {
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		} switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			} next case 0: 0 case 0: if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2; a.length()==cnt[0] a.length() a.length a cnt[0] cnt 0 fin='A' fin 'A' if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2; a.charAt(cnt[next])=='b' a.charAt(cnt[next]) a.charAt a cnt[next] cnt next 'b' next=1 next 1 if(a.charAt(cnt[next])=='c')next=2; a.charAt(cnt[next])=='c' a.charAt(cnt[next]) a.charAt a cnt[next] cnt next 'c' next=2 next 2 cnt[0]++ cnt[0] cnt 0 break; case 1: 1 case 1: if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2; b.length()==cnt[1] b.length() b.length b cnt[1] cnt 1 fin='B' fin 'B' if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2; b.charAt(cnt[next])=='a' b.charAt(cnt[next]) b.charAt b cnt[next] cnt next 'a' next=0 next 0 if(b.charAt(cnt[next])=='c')next=2; b.charAt(cnt[next])=='c' b.charAt(cnt[next]) b.charAt b cnt[next] cnt next 'c' next=2 next 2 cnt[1]++ cnt[1] cnt 1 break; case 2: 2 case 2: if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0; c.length()==cnt[2] c.length() c.length c cnt[2] cnt 2 fin='C' fin 'C' if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0; c.charAt(cnt[next])=='b' c.charAt(cnt[next]) c.charAt c cnt[next] cnt next 'b' next=1 next 1 if(c.charAt(cnt[next])=='a')next=0; c.charAt(cnt[next])=='a' c.charAt(cnt[next]) c.charAt c cnt[next] cnt next 'a' next=0 next 0 cnt[2]++ cnt[2] cnt 2 break; if(fin!='f')break; fin!='f' fin 'f' break; System.out.println(fin) System.out.println System.out System System.out fin String[] args args public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	}
} public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	}
} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		scan.close();
		int cnt[]= {0,0,0};
		int next=0;
		char fin='f';
		while(true){
			switch(next) {
				case 0:
					if(a.length()==cnt[0])fin='A';
					else if(a.charAt(cnt[next])=='b')next=1;
					else if(a.charAt(cnt[next])=='c')next=2;
					cnt[0]++;
					break;
				case 1:
					if(b.length()==cnt[1])fin='B';
					else if(b.charAt(cnt[next])=='a')next=0;
					else if(b.charAt(cnt[next])=='c')next=2;
					cnt[1]++;
					break;
				case 2:
					if(c.length()==cnt[2])fin='C';
					else if(c.charAt(cnt[next])=='b')next=1;
					else if(c.charAt(cnt[next])=='a')next=0;
					cnt[2]++;
					break;
			}
			if(fin!='f')break;
		}
		System.out.println(fin);
	}
}