/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

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();
        int ac = 0;
        int bc = 0;
        int cc = 0;
        char turn = 'a';

        while(true){
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        }

        sc.close();
    }

}


 import java.util.*; util.* java import java.lang.*; lang.* java import java.math.*; math.* java 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();
        int ac = 0;
        int bc = 0;
        int cc = 0;
        char turn = 'a';

        while(true){
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        }

        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();
        int ac = 0;
        int bc = 0;
        int cc = 0;
        char turn = 'a';

        while(true){
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        }

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int ac = 0;
        int bc = 0;
        int cc = 0;
        char turn = 'a';

        while(true){
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        }

        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 int ac = 0; ac 0 int bc = 0; bc 0 int cc = 0; cc 0 char turn = 'a'; turn 'a' while(true){
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        } true {
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        } if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            } turn == 'a' turn 'a' {
                turn = a.charAt(ac);
                ac++;
            } turn = a.charAt(ac) turn a.charAt(ac) a.charAt a ac ac++ ac if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            } turn == 'b' turn 'b' {
                turn = b.charAt(bc);
                bc++;
            } turn = b.charAt(bc) turn b.charAt(bc) b.charAt b bc bc++ bc {
                turn = c.charAt(cc);
                cc++;
            } turn = c.charAt(cc) turn c.charAt(cc) c.charAt c cc cc++ cc if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            } ac == a.length() && turn == 'a' ac == a.length() ac a.length() a.length a turn == 'a' turn 'a' {
                System.out.println("A");
                break;
            } System.out.println("A") System.out.println System.out System System.out "A" break; if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            } bc == b.length() && turn == 'b' bc == b.length() bc b.length() b.length b turn == 'b' turn 'b' {
                System.out.println("B");
                break;
            } System.out.println("B") System.out.println System.out System System.out "B" break; if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            } cc == c.length() && turn == 'c' cc == c.length() cc c.length() c.length c turn == 'c' turn 'c' {
                System.out.println("C");
                break;
            } System.out.println("C") System.out.println System.out System System.out "C" break; sc.close() sc.close sc String[] args args
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

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();
        int ac = 0;
        int bc = 0;
        int cc = 0;
        char turn = 'a';

        while(true){
            if (turn == 'a') {
                turn = a.charAt(ac);
                ac++;
            }else if(turn == 'b'){
                turn = b.charAt(bc);
                bc++;
            }else{
                turn = c.charAt(cc);
                cc++;
            }
            if (ac == a.length() && turn == 'a') {
                System.out.println("A");
                break;
            }
            if (bc == b.length() && turn == 'b') {
                System.out.println("B");
                break;
            }
            if (cc == c.length() && turn == 'c') {
                System.out.println("C");
                break;
            }
        }

        sc.close();
    }

}



