#include <stdio.h>                                                                                                                                                                                        
#include <stdlib.h>                                                                                                                                                                                       
#include <string.h>                                                                                                                                                                                       
                                                                                                                                                                                                          
int main(void)                                                                                                                                                                                            
{                                                                                                                                                                                                         
        char strA[101] = { 0 };                                                                                                                                                                           
        char strB[101] = { 0 };                                                             
        char strC[101] = { 0 };                                                             
        int lenA, lenB, lenC, a = 0, b = 0, c = 0;                                          
        char next = 'a', win;                                                               
                                                                                            
        scanf("%s", strA);                                                              
        scanf("%s", strB);                                                              
        scanf("%s", strC);                                                              
                                                                                        
        lenA = strlen(strA);                                                            
        lenB = strlen(strB);                                                            
        lenC = strlen(strC);                                                            
                                                                                        
        while (1) {                                                                     
                if (next == 'a') {                                                      
                        next = strA[a];                                                 
                        a++;                                                            
                        if (a == lenA + 1) {                                            
                                win = 'A';                                              
                                break;                                                  
                        }                                                               
                } else if (next == 'b') {                                               
                        next = strB[b];                                                  
                        b++;                                                            
                        if (b == lenB + 1) {                                            
                                win = 'B';                                              
                                break;                                                  
                        }                                                               
                } else if (next == 'c') {                                               
                        next = strC[c];                                                 
                        c++;                                                            
                        if (c == lenC + 1) {                                            
                                win = 'C';                                              
                                break;                                                  
                        }                                                               
                }                                                                       
        }                                                                               
        printf("%c\n", win);                                                            
        return 0;                                                                       
}

Measured memory_bytes: 128