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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  } main {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split(""))); A new ArrayList<>(Arrays.asList(sc.nextLine().split(""))) ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split(""))); B new ArrayList<>(Arrays.asList(sc.nextLine().split(""))) ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split(""))); C new ArrayList<>(Arrays.asList(sc.nextLine().split(""))) String popped = A.remove(0); popped A.remove(0) A.remove A 0 while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    } true {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    } if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } popped.equals("a") popped.equals popped "a" {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } if (A.size() == 0) { System.out.println("A"); break; } A.size() == 0 A.size() A.size A 0 { System.out.println("A"); break; } System.out.println("A") System.out.println System.out System System.out "A" break; popped = A.remove(0) popped A.remove(0) A.remove A 0 if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } popped.equals("b") popped.equals popped "b" {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } if (B.size() == 0) { System.out.println("B"); break; } B.size() == 0 B.size() B.size B 0 { System.out.println("B"); break; } System.out.println("B") System.out.println System.out System System.out "B" break; popped = B.remove(0) popped B.remove(0) B.remove B 0 if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } popped.equals("c") popped.equals popped "c" {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } if (C.size() == 0) { System.out.println("C"); break; } C.size() == 0 C.size() C.size C 0 { System.out.println("C"); break; } System.out.println("C") System.out.println System.out System System.out "C" break; popped = C.remove(0) popped C.remove(0) C.remove C 0 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  }
} Main
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    ArrayList<String> A = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> B = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    ArrayList<String> C = new ArrayList<>(Arrays.asList(sc.nextLine().split("")));
    
    String popped = A.remove(0);
    
    while (true) {
      if (popped.equals("a")) {
        if (A.size() == 0) { System.out.println("A"); break; }
        popped = A.remove(0);
      } else if (popped.equals("b")) {
        if (B.size() == 0) { System.out.println("B"); break; }
        popped = B.remove(0);
      } else if (popped.equals("c")) {
        if (C.size() == 0) { System.out.println("C"); break; }
        popped = C.remove(0);
      } 
    }
  }
}
