import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
} Main public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    } main {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    } try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       } catch (IOException e) {
            e.printStackTrace();
       } IOException e {
            e.printStackTrace();
       } e.printStackTrace() e.printStackTrace e {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) String a = br.readLine(); a br.readLine() br.readLine br int aCount = 0; aCount 0 String b = br.readLine(); b br.readLine() br.readLine br int bCount = 0; bCount 0 String c = br.readLine(); c br.readLine() br.readLine br int cCount = 0; cCount 0 String now = "a"; now "a" while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            } true {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            } if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                } "a".equals(now) "a".equals "a" now {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    } aCount >= a.length() aCount a.length() a.length a {
                        System.out.println("A");
                        break;
                    } System.out.println("A") System.out.println System.out System System.out "A" break; now = a.substring(aCount, aCount + 1) now a.substring(aCount, aCount + 1) a.substring a aCount aCount + 1 aCount 1 aCount++ aCount if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                } "b".equals(now) "b".equals "b" now {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    } bCount >= b.length() bCount b.length() b.length b {
                        System.out.println("B");
                        break;
                    } System.out.println("B") System.out.println System.out System System.out "B" break; now = b.substring(bCount, bCount + 1) now b.substring(bCount, bCount + 1) b.substring b bCount bCount + 1 bCount 1 bCount++ bCount if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                } "c".equals(now) "c".equals "c" now {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                } if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    } cCount >= c.length() cCount c.length() c.length c {
                        System.out.println("C");
                        break;
                    } System.out.println("C") System.out.println System.out System System.out "C" break; now = c.substring(cCount, cCount + 1) now c.substring(cCount, cCount + 1) c.substring c cCount cCount + 1 cCount 1 cCount++ cCount String[] args args public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
} public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
}
