import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] STRINGS = new String[3];
    for(int i=0; i<3; i++){
      STRINGS[i] = scanner.next();
    }
    scanner.close();

    int[] index = new int[3];
    int turn = 0;
    char[] ans = {'A', 'B', 'C'};
    boolean isEnd = false;
    while(!isEnd){
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    }
  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] STRINGS = new String[3];
    for(int i=0; i<3; i++){
      STRINGS[i] = scanner.next();
    }
    scanner.close();

    int[] index = new int[3];
    int turn = 0;
    char[] ans = {'A', 'B', 'C'};
    boolean isEnd = false;
    while(!isEnd){
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] STRINGS = new String[3];
    for(int i=0; i<3; i++){
      STRINGS[i] = scanner.next();
    }
    scanner.close();

    int[] index = new int[3];
    int turn = 0;
    char[] ans = {'A', 'B', 'C'};
    boolean isEnd = false;
    while(!isEnd){
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    }
  } main {
    Scanner scanner = new Scanner(System.in);
    String[] STRINGS = new String[3];
    for(int i=0; i<3; i++){
      STRINGS[i] = scanner.next();
    }
    scanner.close();

    int[] index = new int[3];
    int turn = 0;
    char[] ans = {'A', 'B', 'C'};
    boolean isEnd = false;
    while(!isEnd){
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    }
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] STRINGS = new String[3]; STRINGS new String[3] 3 for(int i=0; i<3; i++){
      STRINGS[i] = scanner.next();
    } int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
      STRINGS[i] = scanner.next();
    } {
      STRINGS[i] = scanner.next();
    } STRINGS[i] = scanner.next() STRINGS[i] STRINGS i scanner.next() scanner.next scanner scanner.close() scanner.close scanner int[] index = new int[3]; index new int[3] 3 int turn = 0; turn 0 char[] ans = {'A', 'B', 'C'}; ans {'A', 'B', 'C'} 'A' 'B' 'C' boolean isEnd = false; isEnd false while(!isEnd){
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    } !isEnd isEnd {
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    } index[turn]++ index[turn] index turn for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      } int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      } {
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      } if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        } index[i] == STRINGS[i].length()+1 index[i] index i STRINGS[i].length()+1 STRINGS[i].length() STRINGS[i].length STRINGS[i] STRINGS i 1 {
          System.out.println(ans[i]);
          isEnd = true;
          break;
        } System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i isEnd = true isEnd true break; if(isEnd){
        break;
      } isEnd {
        break;
      } break; switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      } STRINGS[turn].charAt(index[turn]-1) STRINGS[turn].charAt STRINGS[turn] STRINGS turn index[turn]-1 index[turn] index turn 1 case 'a': 'a' case 'a': turn = 0 turn 0 break; case 'b': 'b' case 'b': turn = 1 turn 1 break; case 'c': 'c' case 'c': turn = 2 turn 2 break; String[] args args
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] STRINGS = new String[3];
    for(int i=0; i<3; i++){
      STRINGS[i] = scanner.next();
    }
    scanner.close();

    int[] index = new int[3];
    int turn = 0;
    char[] ans = {'A', 'B', 'C'};
    boolean isEnd = false;
    while(!isEnd){
      index[turn]++;
      for(int i=0; i<3; i++){
        if(index[i] == STRINGS[i].length()+1){
          System.out.println(ans[i]);
          isEnd = true;
          break;
        }
      }
      if(isEnd){
        break;
      }
      switch(STRINGS[turn].charAt(index[turn]-1)){
        case 'a':
          turn = 0;
          break;
        case 'b':
          turn = 1;
          break;
        case 'c':
          turn = 2;
          break;
      }
    }
  }
}
