import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	}
}

 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String a = scanner.next() a scanner.next() scanner.next scanner b = scanner.next() b scanner.next() scanner.next scanner c = scanner.next(); c scanner.next() scanner.next scanner int cta = 0 cta 0 ctb = 0 ctb 0 ctc = 0; ctc 0 cta++ cta String pos = String.valueOf(a.charAt(0)); pos String.valueOf(a.charAt(0)) String.valueOf String a.charAt(0) a.charAt a 0 boolean check = true; check true while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		} check {
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		} switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			} pos case "a": "a" case "a": if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				} cta == a.length() cta a.length() a.length a {
					check = false;
				} check = false check false {
					pos = String.valueOf(a.charAt(cta));
					cta++;
				} pos = String.valueOf(a.charAt(cta)) pos String.valueOf(a.charAt(cta)) String.valueOf String a.charAt(cta) a.charAt a cta cta++ cta break; case "b": "b" case "b": if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				} ctb == b.length() ctb b.length() b.length b {
					check = false;
				} check = false check false {
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				} pos = String.valueOf(b.charAt(ctb)) pos String.valueOf(b.charAt(ctb)) String.valueOf String b.charAt(ctb) b.charAt b ctb ctb++ ctb break; case "c": "c" case "c": if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				} ctc == c.length() ctc c.length() c.length c {
					check = false;
				} check = false check false {
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				} pos = String.valueOf(c.charAt(ctc)) pos String.valueOf(c.charAt(ctc)) String.valueOf String c.charAt(ctc) c.charAt c ctc ctc++ ctc break; switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		} pos case "a": "a" case "a": System.out.println("A") System.out.println System.out System System.out "A" break; case "b": "b" case "b": System.out.println("B") System.out.println System.out System System.out "B" break; case "c": "c" case "c": System.out.println("C") System.out.println System.out System System.out "C" break; String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	}
}


