import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    } main {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next().toUpperCase(); a sc.next().toUpperCase() sc.next().toUpperCase sc.next() sc.next sc String b = sc.next().toUpperCase(); b sc.next().toUpperCase() sc.next().toUpperCase sc.next() sc.next sc String c = sc.next().toUpperCase(); c sc.next().toUpperCase() sc.next().toUpperCase sc.next() sc.next sc List<String> arya = new ArrayList<>(Arrays.asList(a.split(""))); arya new ArrayList<>(Arrays.asList(a.split(""))) List<String> aryb = new ArrayList<>(Arrays.asList(b.split(""))); aryb new ArrayList<>(Arrays.asList(b.split(""))) List<String> aryc = new ArrayList<>(Arrays.asList(c.split(""))); aryc new ArrayList<>(Arrays.asList(c.split(""))) List<String> tempAry = arya; tempAry arya String temp = tempAry.get(0); temp tempAry.get(0) tempAry.get tempAry 0 while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        } temp != null temp null {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        } if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            } temp.equals("A") temp.equals temp "A" {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } tempAry = arya tempAry arya if (tempAry.size() == 0) {
                    break;
                } tempAry.size() == 0 tempAry.size() tempAry.size tempAry 0 {
                    break;
                } break; temp = tempAry.get(0) temp tempAry.get(0) tempAry.get tempAry 0 arya.remove(0) arya.remove arya 0 if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            } temp.equals("B") temp.equals temp "B" {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } tempAry = aryb tempAry aryb if (tempAry.size() == 0) {
                    break;
                } tempAry.size() == 0 tempAry.size() tempAry.size tempAry 0 {
                    break;
                } break; temp = tempAry.get(0) temp tempAry.get(0) tempAry.get tempAry 0 aryb.remove(0) aryb.remove aryb 0 if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            } temp.equals("C") temp.equals temp "C" {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            } tempAry = aryc tempAry aryc if (tempAry.size() == 0) {
                    break;
                } tempAry.size() == 0 tempAry.size() tempAry.size tempAry 0 {
                    break;
                } break; temp = tempAry.get(0) temp tempAry.get(0) tempAry.get tempAry 0 aryc.remove(0) aryc.remove aryc 0 System.out.println(temp) System.out.println System.out System System.out temp String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    }
} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        List<String> arya = new ArrayList<>(Arrays.asList(a.split("")));
        List<String> aryb = new ArrayList<>(Arrays.asList(b.split("")));
        List<String> aryc = new ArrayList<>(Arrays.asList(c.split("")));
        List<String> tempAry = arya;
        String temp = tempAry.get(0);
        while (temp != null) {
            if (temp.equals("A")) {
                tempAry = arya;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                arya.remove(0);
            } else if (temp.equals("B")) {
                tempAry = aryb;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryb.remove(0);
            } else if (temp.equals("C")) {
                tempAry = aryc;
                if (tempAry.size() == 0) {
                    break;
                }
                temp = tempAry.get(0);
                aryc.remove(0);
            }
        }
        System.out.println(temp);
    }
}