import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    }
} Main public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    } main {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] S = new String[3]; S new String[3] 3 for(int i=0;i<3;i++){
            S[i] = sc.next();
        } int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
            S[i] = sc.next();
        } {
            S[i] = sc.next();
        } S[i] = sc.next() S[i] S i sc.next() sc.next sc int next = 0; next 0 boolean end = false; end false String winner = null; winner null while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        } !end end {
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        } if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            } S[next].equals("") S[next].equals S[next] S next "" {
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            } switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                } next case 0: 0 case 0: winner = "A" winner "A" break; case 1: 1 case 1: winner = "B" winner "B" break; case 2: 2 case 2: winner = "C" winner "C" break; end = true end true {
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            } int x = next; x next switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                } S[next].substring(0,1) S[next].substring S[next] S next 0 1 case "a": "a" case "a": next = 0 next 0 break; case "b": "b" case "b": next = 1 next 1 break; case "c": "c" case "c": next = 2 next 2 break; S[x] = S[x].substring(1,S[x].length()) S[x] S x S[x].substring(1,S[x].length()) S[x].substring S[x] S x 1 S[x].length() S[x].length S[x] S x System.out.println(winner) System.out.println System.out System System.out winner String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        for(int i=0;i<3;i++){
            S[i] = sc.next();
        }
        int next = 0;
        boolean end = false;
        String winner = null;
        while(!end){
            if(S[next].equals("")){
                switch(next){
                    case 0:
                        winner = "A";
                        break;
                    case 1:
                        winner = "B";
                        break;
                    case 2:
                        winner = "C";
                        break;
                }
                end = true;
            }else{
                int x = next;
                switch(S[next].substring(0,1)){
                case "a":
                    next = 0;
                    break;
                case "b":
                    next = 1;
                    break;
                case "c":
                    next = 2;
                    break;
                }
                S[x] = S[x].substring(1,S[x].length());
                
            }
            
        }
        System.out.println(winner);
    }
}
