import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
}} import java.util.*; util.* java public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
}} Main public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
} main {
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.next(); A sc.next() sc.next sc String B = sc.next(); B sc.next() sc.next sc String C = sc.next(); C sc.next() sc.next sc int counterA = 0; counterA 0 int counterB = 0; counterB 0 int counterC = 0; counterC 0 char next = 'a'; next 'a' for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  } ; {
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  } {
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  } if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    } next == 'a' next 'a' {
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    } counterA++ counterA if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1); counterA == A.length()+1 counterA A.length()+1 A.length() A.length A 1 {
        System.out.println("A");
        break;
      } System.out.println("A") System.out.println System.out System System.out "A" break; next = A.charAt(counterA-1) next A.charAt(counterA-1) A.charAt A counterA-1 counterA 1 if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    } next == 'b' next 'b' {
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    } counterB++ counterB if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1); counterB == B.length()+1 counterB B.length()+1 B.length() B.length B 1 {
        System.out.println("B");
        break;
      } System.out.println("B") System.out.println System.out System System.out "B" break; next = B.charAt(counterB-1) next B.charAt(counterB-1) B.charAt B counterB-1 counterB 1 if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    } next == 'c' next 'c' {
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    } counterC++ counterC if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1); counterC == C.length()+1 counterC C.length()+1 C.length() C.length C 1 {
        System.out.println("C");
        break;
      } System.out.println("C") System.out.println System.out System System.out "C" break; next = C.charAt(counterC-1) next C.charAt(counterC-1) C.charAt C counterC-1 counterC 1 String[] args args public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
}} public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
}} Main
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
}}