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

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  } main {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) ArrayList<String> sa = new ArrayList<>(); sa new ArrayList<>() for(String s: scanner.next().split("")) {
      sa.add(s);
    } String s scanner.next().split("") scanner.next().split scanner.next() scanner.next scanner "" {
      sa.add(s);
    } {
      sa.add(s);
    } sa.add(s) sa.add sa s ArrayList<String> sb = new ArrayList<>(); sb new ArrayList<>() for(String s: scanner.next().split("")) {
      sb.add(s);
    } String s scanner.next().split("") scanner.next().split scanner.next() scanner.next scanner "" {
      sb.add(s);
    } {
      sb.add(s);
    } sb.add(s) sb.add sb s ArrayList<String> sc = new ArrayList<>(); sc new ArrayList<>() for(String s: scanner.next().split("")) {
      sc.add(s);
    } String s scanner.next().split("") scanner.next().split scanner.next() scanner.next scanner "" {
      sc.add(s);
    } {
      sc.add(s);
    } sc.add(s) sc.add sc s String player = "a"; player "a" while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    } true {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    } if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      } player.equals("a") player.equals player "a" {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } if(sa.size() == 0) {
          System.out.println("A");
          break;
        } sa.size() == 0 sa.size() sa.size sa 0 {
          System.out.println("A");
          break;
        } System.out.println("A") System.out.println System.out System System.out "A" break; player = sa.get(0) player sa.get(0) sa.get sa 0 sa.remove(0) sa.remove sa 0 if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      } player.equals("b") player.equals player "b" {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } if(sb.size() == 0) {
          System.out.println("B");
          break;
        } sb.size() == 0 sb.size() sb.size sb 0 {
          System.out.println("B");
          break;
        } System.out.println("B") System.out.println System.out System System.out "B" break; player = sb.get(0) player sb.get(0) sb.get sb 0 sb.remove(0) sb.remove sb 0 {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      } if(sc.size() == 0) {
          System.out.println("C");
          break;
        } sc.size() == 0 sc.size() sc.size sc 0 {
          System.out.println("C");
          break;
        } System.out.println("C") System.out.println System.out System System.out "C" break; player = sc.get(0) player sc.get(0) sc.get sc 0 sc.remove(0) sc.remove sc 0 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  }
} Main
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    ArrayList<String> sa = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sa.add(s);
    }
    ArrayList<String> sb = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sb.add(s);
    }
    ArrayList<String> sc = new ArrayList<>();
    for(String s: scanner.next().split("")) {
      sc.add(s);
    }
    
    String player = "a";
    
    while(true) {
      if(player.equals("a")) {
        if(sa.size() == 0) {
          System.out.println("A");
          break;
        }
      	player = sa.get(0);
        sa.remove(0);
      } else if(player.equals("b")) {
        if(sb.size() == 0) {
          System.out.println("B");
          break;
        }
      	player = sb.get(0);
        sb.remove(0);        
      } else {
        if(sc.size() == 0) {
          System.out.println("C");
          break;
        }
      	player = sc.get(0);
        sc.remove(0);
      }
    }
  }
}