import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    } main {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder a = new StringBuilder(scan.next()); a new StringBuilder(scan.next()) StringBuilder b = new StringBuilder(scan.next()); b new StringBuilder(scan.next()) StringBuilder c = new StringBuilder(scan.next()); c new StringBuilder(scan.next()) boolean hantei = true; hantei true char turn = a.charAt(0); turn a.charAt(0) a.charAt a 0 a.deleteCharAt(0) a.deleteCharAt a 0 char ans = ' '; ans ' ' while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        } hantei {
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        } if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	} turn == 'a' turn 'a' {
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	} if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		} a.length() == 0 a.length() a.length a 0 {
        			ans = 'A';
        			hantei = false;
        			break;
        		} ans = 'A' ans 'A' hantei = false hantei false break; turn = a.charAt(0) turn a.charAt(0) a.charAt a 0 a.deleteCharAt(0) a.deleteCharAt a 0 if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	} turn == 'b' turn 'b' {
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	} if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		} b.length() == 0 b.length() b.length b 0 {
        			ans = 'B';
        			hantei = false;
        			break;
        		} ans = 'B' ans 'B' hantei = false hantei false break; turn = b.charAt(0) turn b.charAt(0) b.charAt b 0 b.deleteCharAt(0) b.deleteCharAt b 0 if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	} turn == 'c' turn 'c' {
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	} if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		} c.length() == 0 c.length() c.length c 0 {
        			ans = 'C';
        			hantei = false;
        			break;
        		} ans = 'C' ans 'C' hantei = false hantei false break; turn = c.charAt(0) turn c.charAt(0) c.charAt c 0 c.deleteCharAt(0) c.deleteCharAt c 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
} public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
}