import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.List; List java.util class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        }
    }
} Main public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        }
    } main {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        }
    } try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } IOException | NumberFormatException e {
            e.printStackTrace();
            System.exit(0);
        } e.printStackTrace() e.printStackTrace e System.exit(0) System.exit System 0 catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        } final Exception e {
            e.printStackTrace();
            System.exit(0);  
        } e.printStackTrace() e.printStackTrace e System.exit(0) System.exit System 0 {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split(""))); cardsOfA new ArrayList<>(Arrays.asList(br.readLine().split(""))) List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split(""))); cardsOfB new ArrayList<>(Arrays.asList(br.readLine().split(""))) List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split(""))); cardsOfC new ArrayList<>(Arrays.asList(br.readLine().split(""))) String turn = "a"; turn "a" String winner = ""; winner "" while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            } true {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            } if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                } turn.equals("a") turn.equals turn "a" {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    } cardsOfA.size() == 0 cardsOfA.size() cardsOfA.size cardsOfA 0 {
                        winner = "A";
                        break;
                    } winner = "A" winner "A" break; turn = cardsOfA.get(0) turn cardsOfA.get(0) cardsOfA.get cardsOfA 0 cardsOfA.remove(0) cardsOfA.remove cardsOfA 0 if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                } turn.equals("b") turn.equals turn "b" {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    } cardsOfB.size() == 0 cardsOfB.size() cardsOfB.size cardsOfB 0 {
                        winner = "B";
                        break;
                    } winner = "B" winner "B" break; turn = cardsOfB.get(0) turn cardsOfB.get(0) cardsOfB.get cardsOfB 0 cardsOfB.remove(0) cardsOfB.remove cardsOfB 0 if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                } turn.equals("c") turn.equals turn "c" {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                } if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    } cardsOfC.size() == 0 cardsOfC.size() cardsOfC.size cardsOfC 0 {
                        winner = "C";
                        break;
                    } winner = "C" winner "C" break; turn = cardsOfC.get(0) turn cardsOfC.get(0) cardsOfC.get cardsOfC 0 cardsOfC.remove(0) cardsOfC.remove cardsOfC 0 System.out.println(winner) System.out.println System.out System System.out winner final String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> cardsOfA = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfB = new ArrayList<>(Arrays.asList(br.readLine().split("")));
            List<String> cardsOfC = new ArrayList<>(Arrays.asList(br.readLine().split("")));

            String turn = "a";
            String winner = "";
            while (true) {
                if (turn.equals("a")) {
                    if (cardsOfA.size() == 0) {
                        winner = "A";
                        break;
                    }
                    turn = cardsOfA.get(0);
                    cardsOfA.remove(0);
                } else if (turn.equals("b")) {
                    if (cardsOfB.size() == 0) {
                        winner = "B";
                        break;
                    }
                    turn = cardsOfB.get(0);
                    cardsOfB.remove(0);
                } else if (turn.equals("c")) {
                    if (cardsOfC.size() == 0) {
                        winner = "C";
                        break;
                    }
                    turn = cardsOfC.get(0);
                    cardsOfC.remove(0);
                }
            }
            
            System.out.println(winner);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        }
    }
}