import java.util.Scanner;

class Main{
	static int f(String SA, String SB, String SC, int c) {
		if(c == 1) {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		}else if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String SA = sc.next(), SB = sc.next(), SC = sc.next();
		int win = f(SA, SB, SC, 1);
		System.out.println(win == 1 ? "A" : win == 2 ? "B" : "C");
	}
} import java.util.Scanner; Scanner java.util class Main{
	static int f(String SA, String SB, String SC, int c) {
		if(c == 1) {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		}else if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String SA = sc.next(), SB = sc.next(), SC = sc.next();
		int win = f(SA, SB, SC, 1);
		System.out.println(win == 1 ? "A" : win == 2 ? "B" : "C");
	}
} Main static int f(String SA, String SB, String SC, int c) {
		if(c == 1) {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		}else if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		}
	} f {
		if(c == 1) {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		}else if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		}
	} if(c == 1) {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		}else if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		} c == 1 c 1 {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		} if(SA.length() == 0) return 1; SA.length() == 0 SA.length() SA.length SA 0 return 1; 1 int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3; next (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3 (SA.charAt(0) == 'a') SA.charAt(0) SA.charAt SA 0 'a' 1 (SA.charAt(0) == 'b') ? 2 : 3 (SA.charAt(0) == 'b') SA.charAt(0) SA.charAt SA 0 'b' 2 3 return f(SA.substring(1), SB, SC, next); f(SA.substring(1), SB, SC, next) f SA.substring(1) SA.substring SA 1 SB SC next if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		} c == 2 c 2 {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		} if(SB.length() == 0) return 2; SB.length() == 0 SB.length() SB.length SB 0 return 2; 2 int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3; next (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3 (SB.charAt(0) == 'a') SB.charAt(0) SB.charAt SB 0 'a' 1 (SB.charAt(0) == 'b') ? 2 : 3 (SB.charAt(0) == 'b') SB.charAt(0) SB.charAt SB 0 'b' 2 3 return f(SA, SB.substring(1), SC, next); f(SA, SB.substring(1), SC, next) f SA SB.substring(1) SB.substring SB 1 SC next {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		} if(SC.length() == 0) return 3; SC.length() == 0 SC.length() SC.length SC 0 return 3; 3 int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3; next (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3 (SC.charAt(0) == 'a') SC.charAt(0) SC.charAt SC 0 'a' 1 (SC.charAt(0) == 'b') ? 2 : 3 (SC.charAt(0) == 'b') SC.charAt(0) SC.charAt SC 0 'b' 2 3 return f(SA, SB, SC.substring(1), next); f(SA, SB, SC.substring(1), next) f SA SB SC.substring(1) SC.substring SC 1 next String SA SA String SB SB String SC SC int c c public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String SA = sc.next(), SB = sc.next(), SC = sc.next();
		int win = f(SA, SB, SC, 1);
		System.out.println(win == 1 ? "A" : win == 2 ? "B" : "C");
	} main {
		Scanner sc = new Scanner(System.in);
		String SA = sc.next(), SB = sc.next(), SC = sc.next();
		int win = f(SA, SB, SC, 1);
		System.out.println(win == 1 ? "A" : win == 2 ? "B" : "C");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String SA = sc.next() SA sc.next() sc.next sc SB = sc.next() SB sc.next() sc.next sc SC = sc.next(); SC sc.next() sc.next sc int win = f(SA, SB, SC, 1); win f(SA, SB, SC, 1) f SA SB SC 1 System.out.println(win == 1 ? "A" : win == 2 ? "B" : "C") System.out.println System.out System System.out win == 1 ? "A" : win == 2 ? "B" : "C" win == 1 win 1 "A" win == 2 ? "B" : "C" win == 2 win 2 "B" "C" String[] args args
import java.util.Scanner;

class Main{
	static int f(String SA, String SB, String SC, int c) {
		if(c == 1) {
			if(SA.length() == 0) return 1;
			int next = (SA.charAt(0) == 'a') ? 1 : (SA.charAt(0) == 'b') ? 2 : 3;
			return f(SA.substring(1), SB, SC, next);
		}else if(c == 2) {
			if(SB.length() == 0) return 2;
			int next = (SB.charAt(0) == 'a') ? 1 : (SB.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB.substring(1), SC, next);
		}else {
			if(SC.length() == 0) return 3;
			int next = (SC.charAt(0) == 'a') ? 1 : (SC.charAt(0) == 'b') ? 2 : 3;
			return f(SA, SB, SC.substring(1), next);
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String SA = sc.next(), SB = sc.next(), SC = sc.next();
		int win = f(SA, SB, SC, 1);
		System.out.println(win == 1 ? "A" : win == 2 ? "B" : "C");
	}
}