Buggy python submission (verdict: Runtime Error):
a=list(input())
b=list(input())
c=list(input())
#print(a,b,c)

card=a.pop(0)
#print(card)

flag=0
for i in range(len(a)+len(b)+len(c)):
    if card=='a' and len(a)==0 and flag==0:
        ans='A'
        flag=1
    elif card=='b' and len(b)==0 and flag==0:
        ans='B'
        flag=1
    elif card=='c' and len(c)==0 and flag==0:
        ans='C'
        flag=1
    else:
        if card=='a':
            card=a.pop(0)
        elif card=='b':
            card=b.pop(0)
        elif card=='c':
            card=c.pop(0)
    
print(ans)

Fixed submission:
a=list(input())
b=list(input())
c=list(input())
#print(a,b,c)


card=a.pop(0)
#print(card)
flag=0
for i in range(301):
    if card=='a' and len(a)==0 and flag==0:
        ans='A'
        flag=1
    elif card=='b' and len(b)==0 and flag==0:
        ans='B'
        flag=1
    elif card=='c' and len(c)==0 and flag==0:
        ans='C'
        flag=1
    elif flag==0:
        if card=='a':
            card=a.pop(0)
        elif card=='b':
            card=b.pop(0)
        elif card=='c':
            card=c.pop(0)
    
print(ans)

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c=input()

sizea=len(a)
sizeb=len(b)
sizec=len(c)
print(sizea,sizeb,sizec)

flag=1
x=0
y=0
z=0
for i in range(301):
  if flag==1:
    if sizea==0:
      ans='A'
      break
    else:
      if a[x]=='a':
        flag=1
      elif a[x]=='b':
        flag=2
      elif a[x]=='c':
        flag=3
      sizea-=1
      x+=1
      print(sizea,a[x])
  elif flag==2:
    if sizeb==0:
      ans='B'
      break
    else:
      if b[y]=='a':
        flag=1
      elif b[y]=='b':
        flag=2
      elif b[y]=='c':
        flag=3
      sizeb-=1
      y+=1
      print(sizeb,b[y])
  elif flag==3:
    if sizec==0:
      ans='C'
      break
    else:
      if c[z]=='a':
        flag=1
      elif c[z]=='b':
        flag=2
      elif c[z]=='c':
        flag=3
      sizec-=1
      z+=1
      print(sizec,c[z])

print(ans)

Fixed submission:
a=list(input())
b=list(input())
c=list(input())
#print(a,b,c)


card=a.pop(0)
#print(card)
flag=0
for i in range(301):
    if card=='a' and len(a)==0 and flag==0:
        ans='A'
        flag=1
    elif card=='b' and len(b)==0 and flag==0:
        ans='B'
        flag=1
    elif card=='c' and len(c)==0 and flag==0:
        ans='C'
        flag=1
    elif flag==0:
        if card=='a':
            card=a.pop(0)
        elif card=='b':
            card=b.pop(0)
        elif card=='c':
            card=c.pop(0)
    
print(ans)

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c=input()

cnta=len(a)
cntb=len(b)
cntc=len(c)

print(a,b,c)
print(cnta,cntb,cntc)

numa=0
numb=0
numc=0

flag=1
if flag==1:
  numa+=1  
elif flag==2:
  numb+=1
elif flag==3:
  numc+=1

if a[numa]=='a':
  flag=1
elif a[numa]=='b':
  flag=2
elif a[numa]=='c':
  flag=3

if flag==1:
  numa+=1  
elif flag==2:
  numb+=1
elif flag==3:
  numc+=1

print(a[numa])
if a[numa]=='a':
  flag=1
elif a[numa]=='b':
  flag=2
elif a[numa]=='c':
  flag=3
  
numa+=1


Fixed submission:
a=list(input())
b=list(input())
c=list(input())
#print(a,b,c)


card=a.pop(0)
#print(card)
flag=0
for i in range(301):
    if card=='a' and len(a)==0 and flag==0:
        ans='A'
        flag=1
    elif card=='b' and len(b)==0 and flag==0:
        ans='B'
        flag=1
    elif card=='c' and len(c)==0 and flag==0:
        ans='C'
        flag=1
    elif flag==0:
        if card=='a':
            card=a.pop(0)
        elif card=='b':
            card=b.pop(0)
        elif card=='c':
            card=c.pop(0)
    
print(ans)