import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = 1; num 1 char turn = 'a'; turn 'a' int cnt1 = 0; cnt1 0 int cnt2 = 0; cnt2 0 int cnt3 = 0; cnt3 0 String SA = sc.next(); SA sc.next() sc.next sc String SB = sc.next(); SB sc.next() sc.next sc String SC = sc.next(); SC sc.next() sc.next sc for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    } ; {
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    } {
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    } if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      } turn=='a' turn 'a' {
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      } if(cnt1==SA.length()){
          System.out.println('A');
          return;
        } cnt1==SA.length() cnt1 SA.length() SA.length SA {
          System.out.println('A');
          return;
        } System.out.println('A') System.out.println System.out System System.out 'A' return; turn = SA.charAt(cnt1) turn SA.charAt(cnt1) SA.charAt SA cnt1 cnt1++ cnt1 if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      } turn =='b' turn 'b' {
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      } if(cnt2==SB.length()){
          System.out.println('B');
          return;
        } cnt2==SB.length() cnt2 SB.length() SB.length SB {
          System.out.println('B');
          return;
        } System.out.println('B') System.out.println System.out System System.out 'B' return; turn = SB.charAt(cnt2) turn SB.charAt(cnt2) SB.charAt SB cnt2 cnt2++ cnt2 if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      } turn =='c' turn 'c' {
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      } if(cnt3==SC.length()){
          System.out.println('C');
          return;
        } cnt3==SC.length() cnt3 SC.length() SC.length SC {
          System.out.println('C');
          return;
        } System.out.println('C') System.out.println System.out System System.out 'C' return; turn = SC.charAt(cnt3) turn SC.charAt(cnt3) SC.charAt SC cnt3 cnt3++ cnt3 String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  }
}