import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	}
	class B{
		void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		}
		String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		}
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	}
	class B{
		void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		}
		String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		}
	}
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args){
		new Main();
	} main {
		new Main();
	} new Main() String[] args args public Main(){
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	} Main {
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	} new B().doIt() new B().doIt new B() class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	} A void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		} doIt {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		} int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int h = sc.nextInt(); h sc.nextInt() sc.nextInt sc System.out.println((a + b)*h/2) System.out.println System.out System System.out (a + b)*h/2 (a + b)*h (a + b) a b h 2 class B{
		void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		}
		String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		}
	} B void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		} doIt {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		} 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 Ac[] = A.toCharArray(); Ac A.toCharArray() A.toCharArray A char Bc[] = B.toCharArray(); Bc B.toCharArray() B.toCharArray B char Cc[] = C.toCharArray(); Cc C.toCharArray() C.toCharArray C int AL = A.length(); AL A.length() A.length A int BL = B.length(); BL B.length() B.length B int CL = C.length(); CL C.length() C.length C System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL)) System.out.println System.out System System.out Battle(Ac,Bc,Cc,AL,BL,CL) Battle Ac Bc Cc AL BL CL String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		} Battle {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		} int a = 0 a 0 b = 0 b 0 c = 0; c 0 char start = 'a'; start 'a' while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			} true {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			} if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				} start == 'a' start 'a' {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				} a++ a if(a == AL+1)return "A"; a == AL+1 a AL+1 AL 1 return "A"; "A" start = Ac[a-1] start Ac[a-1] Ac a-1 a 1 if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				} start == 'b' start 'b' {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				} b++ b if(b == BL+1)return "B"; b == BL+1 b BL+1 BL 1 return "B"; "B" start = Bc[b-1] start Bc[b-1] Bc b-1 b 1 {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				} c++ c if(c == CL+1)return "C"; c == CL+1 c CL+1 CL 1 return "C"; "C" start = Cc[c-1] start Cc[c-1] Cc c-1 c 1 char Ac[] Ac char Bc[] Bc char Cc[] Cc int AL AL int BL BL int CL CL public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	}
	class B{
		void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		}
		String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		}
	}
} public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	}
	class B{
		void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		}
		String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		}
	}
} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new A().doIt();
		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	}
	class B{
		void doIt() {
			String A = sc.next();
			String B = sc.next();
			String C = sc.next();
			
			char Ac[] = A.toCharArray();
			char Bc[] = B.toCharArray();
			char Cc[] = C.toCharArray();
			
			int AL = A.length();
			int BL = B.length();
			int CL = C.length();
			
			System.out.println(Battle(Ac,Bc,Cc,AL,BL,CL));
		}
		String Battle(char Ac[],char Bc[],char Cc[],int AL,int BL,int CL) {
			int a = 0,b = 0,c = 0;
			char start = 'a';
			while(true) {
				if(start == 'a') {
					a++;
					if(a == AL+1)return "A";
					start = Ac[a-1];
				}else if(start == 'b') {
					b++;
					if(b == BL+1)return "B";
					start = Bc[b-1];
				}else {
					c++;
					if(c == CL+1)return "C";
					start = Cc[c-1];
				}
			}
		}
	}
}
