import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        
        int i=0;
        int num = 1;
        while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        }
    }
    
    public static int selectTurn(String s){
        if(s.equals("a")){
            return 1;
        }
        if(s.equals("b")){
            return 2;
        }
        if(s.equals("c")){
            return 3;
        }
        return 0;
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        
        int i=0;
        int num = 1;
        while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        }
    }
    
    public static int selectTurn(String s){
        if(s.equals("a")){
            return 1;
        }
        if(s.equals("b")){
            return 2;
        }
        if(s.equals("c")){
            return 3;
        }
        return 0;
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        
        int i=0;
        int num = 1;
        while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        
        List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        
        int i=0;
        int num = 1;
        while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split(""))); A new ArrayList<String>(Arrays.asList(sc.next().split(""))) List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split(""))); B new ArrayList<String>(Arrays.asList(sc.next().split(""))) List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split(""))); C new ArrayList<String>(Arrays.asList(sc.next().split(""))) int i=0; i 0 int num = 1; num 1 while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        } true {
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        } switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            } num case 1: 1 case 1: if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    } A.size() > 0 A.size() A.size A 0 {
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    } num = selectTurn(A.get(0)) num selectTurn(A.get(0)) selectTurn A.get(0) A.get A 0 A.remove(0) A.remove A 0 {
                        System.out.println("A");
                        return;
                    } System.out.println("A") System.out.println System.out System System.out "A" return; break; case 2: 2 case 2: if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    } B.size() > 0 B.size() B.size B 0 {
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    } num = selectTurn(B.get(0)) num selectTurn(B.get(0)) selectTurn B.get(0) B.get B 0 B.remove(0) B.remove B 0 {
                        System.out.println("B");
                        return;
                    } System.out.println("B") System.out.println System.out System System.out "B" return; break; case 3: 3 case 3: if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    } C.size() > 0 C.size() C.size C 0 {
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    } num = selectTurn(C.get(0)) num selectTurn(C.get(0)) selectTurn C.get(0) C.get C 0 C.remove(0) C.remove C 0 {
                        System.out.println("C");
                        return;
                    } System.out.println("C") System.out.println System.out System System.out "C" return; break; String[] args args public static int selectTurn(String s){
        if(s.equals("a")){
            return 1;
        }
        if(s.equals("b")){
            return 2;
        }
        if(s.equals("c")){
            return 3;
        }
        return 0;
    } selectTurn {
        if(s.equals("a")){
            return 1;
        }
        if(s.equals("b")){
            return 2;
        }
        if(s.equals("c")){
            return 3;
        }
        return 0;
    } if(s.equals("a")){
            return 1;
        } s.equals("a") s.equals s "a" {
            return 1;
        } return 1; 1 if(s.equals("b")){
            return 2;
        } s.equals("b") s.equals s "b" {
            return 2;
        } return 2; 2 if(s.equals("c")){
            return 3;
        } s.equals("c") s.equals s "c" {
            return 3;
        } return 3; 3 return 0; 0 String s s
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        
        int i=0;
        int num = 1;
        while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        }
    }
    
    public static int selectTurn(String s){
        if(s.equals("a")){
            return 1;
        }
        if(s.equals("b")){
            return 2;
        }
        if(s.equals("c")){
            return 3;
        }
        return 0;
    }
}