import java.util.Scanner;

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();

		char temp = 'a';

		boolean cut = true;
		while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		}
		System.out.println(temp);
		sc.close();
	}
} import java.util.Scanner; Scanner 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();

		char temp = 'a';

		boolean cut = true;
		while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		}
		System.out.println(temp);
		sc.close();
	}
} 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();

		char temp = 'a';

		boolean cut = true;
		while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		}
		System.out.println(temp);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		char temp = 'a';

		boolean cut = true;
		while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		}
		System.out.println(temp);
		sc.close();
	} 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 char temp = 'a'; temp 'a' boolean cut = true; cut true while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		} cut {
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		} switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			} temp case 'a': 'a' case 'a': if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				} a.length() == 0 a.length() a.length a 0 {
					cut = false;
					temp = 'A';
					break;
				} cut = false cut false temp = 'A' temp 'A' break; {
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				} temp = a.charAt(0) temp a.charAt(0) a.charAt a 0 a = a.substring(1) a a.substring(1) a.substring a 1 break; case 'b': 'b' case 'b': if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				} b.length() == 0 b.length() b.length b 0 {
					cut = false;
					temp = 'B';
					break;
				} cut = false cut false temp = 'B' temp 'B' break; {
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				} temp = b.charAt(0) temp b.charAt(0) b.charAt b 0 b = b.substring(1) b b.substring(1) b.substring b 1 break; case 'c': 'c' case 'c': if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				} c.length() == 0 c.length() c.length c 0 {
					cut = false;
					temp = 'C';
					break;
				} cut = false cut false temp = 'C' temp 'C' break; {
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				} temp = c.charAt(0) temp c.charAt(0) c.charAt c 0 c = c.substring(1) c c.substring(1) c.substring c 1 break; System.out.println(temp) System.out.println System.out System System.out temp sc.close() sc.close sc String[] args args
import java.util.Scanner;

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();

		char temp = 'a';

		boolean cut = true;
		while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		}
		System.out.println(temp);
		sc.close();
	}
}
