import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  }
} Main public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  } main {
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.nextLine(); A sc.nextLine() sc.nextLine sc String B = sc.nextLine(); B sc.nextLine() sc.nextLine sc String C = sc.nextLine(); C sc.nextLine() sc.nextLine sc String turn = "A"; turn "A" while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    } true {
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    } if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      } turn.equals("A") turn.equals turn "A" {
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      } if(A.length() == 0){
          break;
        } A.length() == 0 A.length() A.length A 0 {
          break;
        } break; char z = A.charAt(0); z A.charAt(0) A.charAt A 0 A = A.substring(1, A.length()) A A.substring(1, A.length()) A.substring A 1 A.length() A.length A if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        } z == 'a' z 'a' {
          turn = "A";
        } turn = "A" turn "A" if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        } z == 'b' z 'b' {
          turn = "B";
        } turn = "B" turn "B" {
          turn = "C";
        } turn = "C" turn "C" if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      } turn.equals("B") turn.equals turn "B" {
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      } if(B.length() == 0){
          break;
        } B.length() == 0 B.length() B.length B 0 {
          break;
        } break; char z = B.charAt(0); z B.charAt(0) B.charAt B 0 B = B.substring(1, B.length()) B B.substring(1, B.length()) B.substring B 1 B.length() B.length B if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        } z == 'a' z 'a' {
          turn = "A";
        } turn = "A" turn "A" if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        } z == 'b' z 'b' {
          turn = "B";
        } turn = "B" turn "B" {
          turn = "C";
        } turn = "C" turn "C" {
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      } if(C.length() == 0){
          break;
        } C.length() == 0 C.length() C.length C 0 {
          break;
        } break; char z = C.charAt(0); z C.charAt(0) C.charAt C 0 C = C.substring(1, C.length()) C C.substring(1, C.length()) C.substring C 1 C.length() C.length C if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        } z == 'a' z 'a' {
          turn = "A";
        } turn = "A" turn "A" if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        } z == 'b' z 'b' {
          turn = "B";
        } turn = "B" turn "B" {
          turn = "C";
        } turn = "C" turn "C" System.out.println(turn) System.out.println System.out System System.out turn String[]args args public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  }
} public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  }
}