import java.util.*;

public 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    }
    
} import java.util.*; util.* java public 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    }
    
} 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    } 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    } 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 turns = 'a'; turns 'a' while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        } true {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        } if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            } turns == 'a' && Ac >= A.length() turns == 'a' turns 'a' Ac >= A.length() Ac A.length() A.length A {
                System.out.println("A");
                return;
            } System.out.println("A") System.out.println System.out System System.out "A" return; if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            } turns == 'b' && Bc >= B.length() turns == 'b' turns 'b' Bc >= B.length() Bc B.length() B.length B {
                System.out.println("B");
                return;
            } System.out.println("B") System.out.println System.out System System.out "B" return; if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            } turns == 'c' && Cc >= C.length() turns == 'c' turns 'c' Cc >= C.length() Cc C.length() C.length C {
                System.out.println("C");
                return;
            } System.out.println("C") System.out.println System.out System System.out "C" return; char turn = 0; turn 0 if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            } turns == 'a' turns 'a' {
                turn = A.charAt(Ac);
                Ac++;
            } turn = A.charAt(Ac) turn A.charAt(Ac) A.charAt A Ac Ac++ Ac if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            } turns == 'b' turns '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 switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            } turn case 'a' : 'a' case 'a' : turns = 'a' turns 'a' break; case 'b' : 'b' case 'b' : turns = 'b' turns 'b' break; case 'c' : 'c' case 'c' : turns = 'c' turns 'c' String[] args args public 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    }
    
} public 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    }
    
} Main
import java.util.*;

public 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 turns = 'a';
        while (true) {
            if (turns == 'a' && Ac >= A.length()) {
                System.out.println("A");
                return;
            } else if (turns == 'b' && Bc >= B.length()) {
                System.out.println("B");
                return;
            } else if (turns == 'c' && Cc >= C.length()) {
                System.out.println("C");
                return;
            }
            char turn = 0;
            if (turns == 'a') {
                turn = A.charAt(Ac);
                Ac++;
            } else if (turns == 'b') {
                turn = B.charAt(Bc);
                Bc++;
            } else {
                turn = C.charAt(Cc);
                Cc++;
            }
            switch(turn) {
            case 'a' :
                turns = 'a';
                break;
            case 'b' :
                turns = 'b';
                break;
            case 'c' :
                turns = 'c';
            }
        }
    }
    
}
