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 aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  }
} 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 aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  }
} 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 aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    int aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  } 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 aIndex = 1; aIndex 1 int bIndex = 0; bIndex 0 int cIndex = 0; cIndex 0 char tmp = a.charAt(0); tmp a.charAt(0) a.charAt a 0 while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    } true {
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    } switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      } tmp case 'a': 'a' case 'a': if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          } a.length() == aIndex a.length() a.length a aIndex {
            System.out.println("A");
            System.exit(0);
          } System.out.println("A") System.out.println System.out System System.out "A" System.exit(0) System.exit System 0 tmp = a.charAt(aIndex++) tmp a.charAt(aIndex++) a.charAt a aIndex++ aIndex break; case 'b': 'b' case 'b': if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          } b.length() == bIndex b.length() b.length b bIndex {
            System.out.println("B");
            System.exit(0);
          } System.out.println("B") System.out.println System.out System System.out "B" System.exit(0) System.exit System 0 tmp = b.charAt(bIndex++) tmp b.charAt(bIndex++) b.charAt b bIndex++ bIndex break; case 'c': 'c' case 'c': if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          } c.length() == cIndex c.length() c.length c cIndex {
            System.out.println("C");
            System.exit(0);
          } System.out.println("C") System.out.println System.out System System.out "C" System.exit(0) System.exit System 0 tmp = c.charAt(cIndex++) tmp c.charAt(cIndex++) c.charAt c cIndex++ cIndex break; 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 aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  }
} 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 aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  }
} 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 aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  }
}