
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    }
} Main private static Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    } main {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    } String SA = scan.next(); SA scan.next() scan.next scan String SB = scan.next(); SB scan.next() scan.next scan String SC = scan.next(); SC scan.next() scan.next scan int sa = 0; sa 0 int sb = 0; sb 0 int sc = 0; sc 0 char next = 'a'; next 'a' boolean flag = true; flag true char winner = 0; winner 0 while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	} flag {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	} switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    } next case 'a': 'a' case 'a': if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    } sa == SA.length() sa SA.length() SA.length SA {
			flag = false;
			winner = 'A';
		    } flag = false flag false winner = 'A' winner 'A' {
			next = SA.charAt(sa);
			sa++;
		    } next = SA.charAt(sa) next SA.charAt(sa) SA.charAt SA sa sa++ sa break; case 'b': 'b' case 'b': if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    } sb == SB.length() sb SB.length() SB.length SB {
			flag = false;
			winner = 'B';
		    } flag = false flag false winner = 'B' winner 'B' {
			next = SB.charAt(sb);
			sb++;
		    } next = SB.charAt(sb) next SB.charAt(sb) SB.charAt SB sb sb++ sb break; case 'c': 'c' case 'c': if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    } sc == SC.length() sc SC.length() SC.length SC {
			flag = false;
			winner = 'C';
		    } flag = false flag false winner = 'C' winner 'C' {
			next = SC.charAt(sc);
			sc++;
		    } next = SC.charAt(sc) next SC.charAt(sc) SC.charAt SC sc sc++ sc break; System.out.println(winner) System.out.println System.out System System.out winner scan.close() scan.close scan String[] args args public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    }
} public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    }
} Main

import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    }
}
