import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    }
} Main public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    } main {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String SA = sc.next(); SA sc.next() sc.next sc String SB = sc.next(); SB sc.next() sc.next sc String SC = sc.next(); SC sc.next() sc.next sc int counta= -1; counta -1 1 int countb= -1; countb -1 1 int countc= -1; countc -1 1 int idx = 0; idx 0 boolean judge =true; judge true while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        } judge {
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        } if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            } idx == 0 idx 0 {
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        } counta++ counta if(counta == SA.length()){
                    break;
                } counta == SA.length() counta SA.length() SA.length SA {
                    break;
                } break; if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                } SA.charAt(counta) == 'b' SA.charAt(counta) SA.charAt SA counta 'b' {
                    idx = 1;
                } idx = 1 idx 1 if(SA.charAt(counta) == 'c'){
                    idx = 2;
                } SA.charAt(counta) == 'c' SA.charAt(counta) SA.charAt SA counta 'c' {
                    idx = 2;
                } idx = 2 idx 2 if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            } idx == 1 idx 1 {
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            } countb++ countb if(countb == SB.length()){
                    break;
                } countb == SB.length() countb SB.length() SB.length SB {
                    break;
                } break; if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                } SB.charAt(countb) == 'a' SB.charAt(countb) SB.charAt SB countb 'a' {
                    idx = 0;
                } idx = 0 idx 0 if(SB.charAt(countb) == 'c'){
                    idx = 2;
                } SB.charAt(countb) == 'c' SB.charAt(countb) SB.charAt SB countb 'c' {
                    idx = 2;
                } idx = 2 idx 2 {
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            } countc++ countc if(countc == SC.length()){
                    break;
                } countc == SC.length() countc SC.length() SC.length SC {
                    break;
                } break; if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                } SC.charAt(countc) == 'a' SC.charAt(countc) SC.charAt SC countc 'a' {
                    idx = 0;
                } idx = 0 idx 0 if(SC.charAt(countc) == 'b'){
                    idx = 1;
                } SC.charAt(countc) == 'b' SC.charAt(countc) SC.charAt SC countc 'b' {
                    idx = 1;
                } idx = 1 idx 1 if(counta == SA.length()) System.out.println("A"); counta == SA.length() counta SA.length() SA.length SA System.out.println("A") System.out.println System.out System System.out "A" if(countb == SB.length()) System.out.println("B"); countb == SB.length() countb SB.length() SB.length SB System.out.println("B") System.out.println System.out System System.out "B" if(countc == SC.length()) System.out.println("C"); countc == SC.length() countc SC.length() SC.length SC System.out.println("C") System.out.println System.out System System.out "C" String[] args args public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    }
} public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();
        
        int counta= -1;
        int countb= -1;
        int countc= -1;
        int idx = 0;
        boolean judge =true;
        
        while(judge){
            if(idx == 0){
                counta++;
                if(counta == SA.length()){
                    break;
                }
                if(SA.charAt(counta) == 'b'){
                    idx = 1;
                }else if(SA.charAt(counta) == 'c'){
                    idx = 2;
                }
        }else if(idx == 1){
                countb++;
                if(countb == SB.length()){
                    break;
                }
                if(SB.charAt(countb) == 'a'){
                    idx = 0;
                }
                else if(SB.charAt(countb) == 'c'){
                    idx = 2;
                }
            }else{
                countc++;
                if(countc == SC.length()){
                    break;
                }
                if(SC.charAt(countc) == 'a'){
                    idx = 0;
                }else if(SC.charAt(countc) == 'b'){
                    idx = 1;
                }
            }
        }
        
        if(counta == SA.length()) System.out.println("A");
        if(countb == SB.length()) System.out.println("B");
        if(countc == SC.length()) System.out.println("C");
        
    }
}
