import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S[] = new String[3]; S new String[3] 3 for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		} int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
			S[i] = sc.next();
		} {
			S[i] = sc.next();
		} S[i] = sc.next() S[i] S i sc.next() sc.next sc int a[] = new int[3]; a new int[3] 3 int now = 0; now 0 while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		} true {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		} int temp = now; temp now if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			} S[now].length()==a[now] S[now].length() S[now].length S[now] S now a[now] a now {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			} switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				} now case 0: 0 case 0: System.out.println("A") System.out.println System.out System System.out "A" return; case 1: 1 case 1: System.out.println("B") System.out.println System.out System System.out "B" return ; case 2: 2 case 2: System.out.println("C") System.out.println System.out System System.out "C" return ; switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			} S[now].charAt(a[now]) S[now].charAt S[now] S now a[now] a now case 'a': 'a' case 'a': now = 0 now 0 break; case 'b': 'b' case 'b': now = 1 now 1 break; case 'c': 'c' case 'c': now = 2 now 2 break; a[temp]++ a[temp] a temp String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S[] = new String[3];
		for (int i = 0; i < 3; i++) {
			S[i] = sc.next();
		}
		int a[] = new int[3];
		int now = 0;
		while (true) {
			int temp = now;
			if (S[now].length()==a[now]) {
				switch(now) {
				case 0: System.out.println("A");return;
				case 1: System.out.println("B");return ;
				case 2: System.out.println("C");return ;
				}
			}
			switch (S[now].charAt(a[now])) {
			case 'a':
				now = 0;
				break;
			case 'b':
				now = 1;
				break;
			case 'c':
				now = 2;
				break;
			}
			a[temp]++;
		}
	}
}
