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();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  }
} 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();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  }
} 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();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  } main {
    Scanner sc  = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  } 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 final int al = a.length(); al a.length() a.length a final int bl = b.length(); bl b.length() b.length b final int cl = c.length(); cl c.length() c.length c int aa = al; aa al int bb = bl; bb bl int cc = cl; cc cl char judge = a.charAt(al - aa); judge a.charAt(al - aa) a.charAt a al - aa al aa aa = aa - 1 aa aa - 1 aa 1 while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    } true {
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    } if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      } judge == 'a' judge 'a' {
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      } if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        } aa == 0 aa 0 {break;} break; {
        judge = a.charAt(al - aa);
        aa = aa -1;
        } judge = a.charAt(al - aa) judge a.charAt(al - aa) a.charAt a al - aa al aa aa = aa -1 aa aa -1 aa 1 if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      } judge == 'b' judge 'b' {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      } if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        } bb == 0 bb 0 {break;} break; {
        judge = b.charAt(bl - bb);
        bb = bb -1;
        } judge = b.charAt(bl - bb) judge b.charAt(bl - bb) b.charAt b bl - bb bl bb bb = bb -1 bb bb -1 bb 1 if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      } judge == 'c' judge 'c' {
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      } if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        } cc == 0 cc 0 {break;} break; {
        judge = c.charAt(cl - cc);
        cc = cc -1;
        } judge = c.charAt(cl - cc) judge c.charAt(cl - cc) c.charAt c cl - cc cl cc cc = cc -1 cc cc -1 cc 1 if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");} judge == 'a' judge 'a' {System.out.println("A");} System.out.println("A") System.out.println System.out System System.out "A" if(judge == 'b'){System.out.println("B");}else{System.out.println("C");} judge == 'b' judge 'b' {System.out.println("B");} System.out.println("B") System.out.println System.out System System.out "B" {System.out.println("C");} System.out.println("C") System.out.println System.out System System.out "C" 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();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  }
} 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();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  }
} 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();
    final int al = a.length();
    final int bl = b.length();
    final int cl = c.length();
    int aa = al;
    int bb = bl;
    int cc = cl;
    char judge = a.charAt(al - aa);
    aa = aa - 1;
    while(true){
      if(judge == 'a'){
        if(aa == 0){break;}else{
        judge = a.charAt(al - aa);
        aa = aa -1;
        }
      }else if (judge == 'b') {
        if(bb == 0){break;}else{
        judge = b.charAt(bl - bb);
        bb = bb -1;
        }
      }else if(judge == 'c'){
        if(cc == 0){break;}else{
        judge = c.charAt(cl - cc);
        cc = cc -1;
        }
      }
    }
    if(judge == 'a'){System.out.println("A");}else if(judge == 'b'){System.out.println("B");}else{System.out.println("C");}
  }
}
