import java.util.ArrayDeque;
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	}
	static class D extends ArrayDeque<Character>{}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Scanner; Scanner java.util public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	}
	static class D extends ArrayDeque<Character>{}
} Main static final Scanner s=new Scanner(System.in); s new Scanner(System.in) public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	} main {
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	} D[] deques = new D[3]; deques new D[3] 3 for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		} int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		} {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		} deques[i]=new D() deques[i] deques i new D() for(char c:s.next().toCharArray())
				deques[i].add(c); char c s.next().toCharArray() s.next().toCharArray s.next() s.next s deques[i].add(c); deques[i].add(c) deques[i].add deques[i] deques i c char next='a'; next 'a' while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		} !deques[next-'a'].isEmpty() deques[next-'a'].isEmpty() deques[next-'a'].isEmpty deques[next-'a'] deques next-'a' next 'a' {
			next=deques[next-'a'].poll();
		} next=deques[next-'a'].poll() next deques[next-'a'].poll() deques[next-'a'].poll deques[next-'a'] deques next-'a' next 'a' System.out.println(Character.toUpperCase(next)) System.out.println System.out System System.out Character.toUpperCase(next) Character.toUpperCase Character next String[] __ __ static class D extends ArrayDeque<Character>{} D ArrayDeque public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	}
	static class D extends ArrayDeque<Character>{}
} public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	}
	static class D extends ArrayDeque<Character>{}
} Main
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		D[] deques = new D[3];
		for(int i=0;i<3;i++) {
			deques[i]=new D();
			for(char c:s.next().toCharArray())
				deques[i].add(c);
		}
		char next='a';
		while(!deques[next-'a'].isEmpty()) {
			next=deques[next-'a'].poll();
		}
		System.out.println(Character.toUpperCase(next));
	}
	static class D extends ArrayDeque<Character>{}
}