import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  }

} import java.util.*; util.* java import java.math.*; math.* java public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  }

} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  } main {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String aString = sc.next(); aString sc.next() sc.next sc String bString = sc.next(); bString sc.next() sc.next sc String cString = sc.next(); cString sc.next() sc.next sc int i = 0; i 0 int j = 0; j 0 int k = 0; k 0 char now = 'a'; now 'a' while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    } true {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    } if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      } now == 'a' now 'a' {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } if (i == aString.length()) {
          System.out.println("A");
          return;
        } i == aString.length() i aString.length() aString.length aString {
          System.out.println("A");
          return;
        } System.out.println("A") System.out.println System.out System System.out "A" return; now = aString.charAt(i) now aString.charAt(i) aString.charAt aString i i++ i if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      } now == 'b' now 'b' {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } if (j == bString.length()) {
          System.out.println("B");
          return;
        } j == bString.length() j bString.length() bString.length bString {
          System.out.println("B");
          return;
        } System.out.println("B") System.out.println System.out System System.out "B" return; now = bString.charAt(j) now bString.charAt(j) bString.charAt bString j j++ j if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      } now == 'c' now 'c' {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      } if (k == cString.length()) {
          System.out.println("C");
          return;
        } k == cString.length() k cString.length() cString.length cString {
          System.out.println("C");
          return;
        } System.out.println("C") System.out.println System.out System System.out "C" return; now = cString.charAt(k) now cString.charAt(k) cString.charAt cString k k++ k String[] args args public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  }

} public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  }

} Main
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String aString = sc.next();
    String bString = sc.next();
    String cString = sc.next();

    int i = 0;
    int j = 0;
    int k = 0;

    char now = 'a';

    while (true) {
      if (now == 'a') {
        if (i == aString.length()) {
          System.out.println("A");
          return;
        }
        now = aString.charAt(i);
        i++;
      } else if (now == 'b') {
        if (j == bString.length()) {
          System.out.println("B");
          return;
        }
        now = bString.charAt(j);
        j++;
      } else if (now == 'c') {
        if (k == cString.length()) {
          System.out.println("C");
          return;
        }
        now = cString.charAt(k);
        k++;
      }
    }


  }

}
