qyliang/CodeNanoFix huggingface dataset:
Buggy code:
S = dict()

S['a'] = input()[::-1]
S['b'] = input()[::-1]
S['c'] = input()[::-1]

player = 'a'

while S[player]:
  player = S[player].pop()

  
res = player.upper()
print(res)
  

Fixed code:
S = dict()

S['a'] = list(input())[::-1]
S['b'] = list(input())[::-1]
S['c'] = list(input())[::-1]

player = 'a'

while S[player]:
  player = S[player].pop()

  
res = player.upper()
print(res)
Buggy code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a =input()
    b=input()
    c=input()
    now = "A"
    for i in range(300):
        if now =="A":
            if len(a) >0:
                now = a.pop().upper()
            else:
                print("A")
                break
        if now =="B":
            if len(b) >0:
                now = b.pop().upper()
            else:
                print("B")
                break
        if now =="C":
            if len(c) >0:
                now = c.pop().upper()
            else:
                print("C")
                break

Fixed code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a =input()
    b=input()
    c=input()
    now = "A"
    for i in range(300):
        if now =="A":
            if len(a) >0:
                now = a[0].upper()
                a=a[1:]
            else:
                print("A")
                break
        if now =="B":
            if len(b) >0:
                now = b[0].upper()
                b=b[1:]
            else:
                print("B")
                break
        if now =="C":
            if len(c) >0:
                now = c[0].upper()
                c=c[1:]
            else:
                print("C")
                break
Buggy code:

# -*- coding: utf-8 -*-
# problem B
player = {i:list(input()) for i in 'abc'}

t = 'a'
while True:
    if len(player[t]) == 0:
        break
    else:
        x = p[t][0]
        p[t].pop(0)
        t = x

print(t.upper())

Fixed code:

# -*- coding: utf-8 -*-
# problem B
player = {i:list(input()) for i in 'abc'}

t = 'a'
while True:
    if len(player[t]) == 0:
        break
    else:
        x = player[t][0]
        player[t].pop(0)
        t = x

print(t.upper())
Buggy code:
a=list(input())
b=list(input())
c=list(input())
next=a.pop(0)
while True:
  if next=="a":
    if not a:
      print("A")
      break
    else:
      next=a.pop(0)
  elif next=="b":
    if not b:
      print("B")
      break
    else:
      next=b.pop(0)
  else :
    if not b:
      print("C")
      break
    else:
      next=c.pop(0)
    

Fixed code:
a=list(input())
b=list(input())
c=list(input())
next=a.pop(0)
while True:
  if next=="a":
    if not a:
      print("A")
      break
    else:
      next=a.pop(0)
  elif next=="b":
    if not b:
      print("B")
      break
    else:
      next=b.pop(0)
  else :
    if not c:
      print("C")
      break
    else:
      next=c.pop(0)
Buggy code:
Sa = input()
Sb = input()
Sc = input()
data = [Sa, Sb, Sc]
print(data[0][0])
target = 0
while True:
    print(data)
    if(data[target] == ""):
        if target == 0:
            print("A")
        if target == 1:
            print("B")
        if target == 2:
            print("C")
        break
    if data[target][0] == "a":
        data[target] = data[target][1:]
        target = 0
    elif data[target][0] == "b":
        data[target] = data[target][1:]
        target = 1
    elif data[target][0] == "c":
        data[target] = data[target][1:]
        target = 2

Fixed code:
Sa = input()
Sb = input()
Sc = input()
data = [Sa, Sb, Sc]
target = 0
while True:
    if(data[target] == ""):
        if target == 0:
            print("A")
        if target == 1:
            print("B")
        if target == 2:
            print("C")
        break
    if data[target][0] == "a":
        data[target] = data[target][1:]
        target = 0
    elif data[target][0] == "b":
        data[target] = data[target][1:]
        target = 1
    elif data[target][0] == "c":
        data[target] = data[target][1:]
        target = 2
Buggy code:
import sys
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

tmp="a"

while True:
    if tmp=="a":
        if len(sa)==0:
            print("A")
            sys.exit()
        else:
            tmp=sa[0]
            sa=sa.lstrip(sa[0])
    elif tmp=="b":
        if len(sb)==0:
            print("B")
            sys.exit()
        else:
            tmp=sb[0]
            sb=sb.lstrip(sb[0])
    elif tmp=="c":      
        if len(sc)==0:
            print("C")
            sys.exit()
        else:
            tmp=sc[0]
            sc=sc.lstrip(sc[0])

Fixed code:
import sys
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

tmp="a"

while True:
    if tmp=="a":
        if len(sa)==0:
            print("A")
            sys.exit()
        else:
            tmp=sa[0]
            sa.pop(0)
    elif tmp=="b":
        if len(sb)==0:
            print("B")
            sys.exit()
        else:
            tmp=sb[0]
            sb.pop(0)
    elif tmp=="c":      
        if len(sc)==0:
            print("C")
            sys.exit()
        else:
            tmp=sc[0]
            sc.pop(0)
Buggy code:
a = input()
b = input()
c = input()
d = a + b + c
def turn(x ,a_hand ,b_hand ,c_hand):
    if not a_hand:
        print("A")
        return
    if not b_hand:
        print("B")
        return
    if not c_hand:
        print("C")
        return
    if x == "a":
        x = a_hand[0]
        a_hand = a_hand[1:]
        turn(x , a_hand , b_hand , c_hand)
    elif x == "b":
        x = b_hand[0]
        b_hand = b_hand[1:]
        turn(x , a_hand , b_hand , c_hand)
    else:
        x = c_hand[0]
        c_hand = c_hand[1:]
        turn(x , a_hand , b_hand , c_hand)
turn("a",a,b,c)

Fixed code:
a = input()
b = input()
c = input()
def turn(x ,a_hand ,b_hand ,c_hand):
    if not a_hand and x == "a":
        print("A")
        return
    if not b_hand and x =="b":
        print("B")
        return
    if not c_hand and x =="c":
        print("C")
        return
    if x == "a":
        x = a_hand[0]
        a_hand = a_hand[1:]
        turn(x , a_hand , b_hand , c_hand)
    elif x == "b":
        x = b_hand[0]
        b_hand = b_hand[1:]
        turn(x , a_hand , b_hand , c_hand)
    else:
        x = c_hand[0]
        c_hand = c_hand[1:]
        turn(x , a_hand , b_hand , c_hand)
turn("a",a,b,c)
Buggy code:
A = list(input())
B = list(input())
C = list(input())

X = 'a'
while True:
  if X == 'a':
    if len(A)==0:
      print('a')
      exit()
    else:
      X = A.pop(0)
  elif X == 'b':
    if len(B)==0:
      print('b')
      exit()
    else:
      X = B.pop(0)
  elif X == 'c':
    if len(C)==0:
      print('c')
      exit()
    else:
      X = C.pop(0)

Fixed code:
A = list(input())
B = list(input())
C = list(input())

X = 'a'
while True:
  if X == 'a':
    if len(A)==0:
      print('A')
      exit()
    else:
      X = A.pop(0)
  elif X == 'b':
    if len(B)==0:
      print('B')
      exit()
    else:
      X = B.pop(0)
  elif X == 'c':
    if len(C)==0:
      print('C')
      exit()
    else:
      X = C.pop(0)
Buggy code:
a_list = list(input())
#print(a_list)
b_list = list(input())
#print(b_list)
c_list = list(input())
#print(c_list)
x=a_list.pop(0)
while True:
    if x=="a":
        x = a_list.pop(0)
    elif x == "b":
        x = b_list.pop(0)
    else:
        x = c_list.pop(0)
    if len(a_list)==0:
        print("A")
        break
    elif len(b_list)==0:
        print("B")
        break
    elif len(c_list):
        print("C")
        break

Fixed code:
a_list = list(input())
b_list = list(input())
c_list = list(input())
x=a_list.pop(0)
while True:
    if x=="a":
        if len(a_list)==0:
            print("A")
            break
        else:
            x = a_list.pop(0)
    elif x == "b":
        if len(b_list)==0:
            print("B")
            break
        else:
            x = b_list.pop(0)
    else:
        if len(c_list)==0:
            print("C")
            break
        else:
            x = c_list.pop(0)
Buggy code:
A = input()
B = input()
C = input()

cards = {'a':A, 'b':B, 'c':C}

def play(cards):
    p = 'a'
    while True:
        cs = cards[p]
        if len(cs) == 0:
            return p
        next = cs[0]
        cards[p] = cs[1:]
        p = next

play(cards)


Fixed code:
A = input()
B = input()
C = input()

cards = {'a':A, 'b':B, 'c':C}

def play(cards):
    p = 'a'
    while True:
        cs = cards[p]
        if len(cs) == 0:
            return p.upper()
        next = cs[0]
        cards[p] = cs[1:]
        p = next

print(play(cards))
Buggy code:
A=input()
B=input()
C=input()
s="a"
while len(A)!=0 and len(B)!=0 and len(C)!=0:
  if s=="a":
    if A[0]=="b":
      s="b"
    elif A[0]=="c":
      s="c"
    A=A[1:]
  elif s=="b":
    if B[0]=="c":
      s="c"
    elif B[0]=="a":
      s="a"
    B=B[1:]
  else:
    if C[0]=="b":
      s="b"
    elif C[0]=="a":
      s="a"
    C=C[1:]
if len(A)==0:
  print("A")
elif len(B)==0:
  print("B")
else:
  print("C")

Fixed code:
A=input()
B=input()
C=input()
s="a"
while (len(A)!=0 or s!="a") and (len(B)!=0 or s!="b") and (len(C)!=0 or s!="c"):
  if s=="a":
    s=A[0]
    A=A[1:]
  elif s=="b":
    s=B[0]
    B=B[1:]
  else:
    s=C[0]
    C=C[1:]
if len(A)==0 and s=="a":
    print("A")
elif len(B)==0 and s=="b":
    print("B")
else:
    print("C")
Buggy code:
sa=list(input())
sb=list(input())
sc=list(input())
owner="a"
while True:
    if owner=="a":
        if len(A):
            owner=A[0]
            del A[0]
        else:
            break
    elif owner=="b":
        if len(B):
            owner=B[0]
            del B[0]
        else:
            break
    else:
        if len(C):
            owner=C[0]
            del C[0]
        else:
            break
if owner=="a":
    print("A")
elif owner=="b":
    print("B")
else:
    print("C")

Fixed code:
sa=list(input())
sb=list(input())
sc=list(input())
owner="a"
while True:
    if owner=="a":
        if len(sa):
            owner=sa[0]
            del sa[0]
        else:
            break
    elif owner=="b":
        if len(sb):
            owner=sb[0]
            del sb[0]
        else:
            break
    else:
        if len(sc):
            owner=sc[0]
            del sc[0]
        else:
            break
if owner=="a":
    print("A")
elif owner=="b":
    print("B")
else:
    print("C")
Buggy code:
a = list(input())
b = list(input())
c = list(input())
key = "a"
for i in range(300):
  if key = "a":
    if len(a) == 0:
      print("A")
      break
    else:
      key = a[0]
      a = a[1:]
      
  elif key = "b":
    if len(b) == 0:
      print("B")
      break
    else:
      key = b[0]
      b = b[1:]
      
  else:
    if len(c) == 0:
      print("C")
      break
    else:
      key = c[0]
      c = c[1:]
    
      

Fixed code:
a = list(input())
b = list(input())
c = list(input())
key = "a"
for i in range(300):
  if key == "a":
    if len(a) == 0:
      print("A")
      break
    else:
      key = a[0]
      a = a[1:]
      
  elif key == "b":
    if len(b) == 0:
      print("B")
      break
    else:
      key = b[0]
      b = b[1:]
      
  else:
    if len(c) == 0:
      print("C")
      break
    else:
      key = c[0]
      c = c[1:]
Buggy code:
a = input()
b = input()
c = input()
abc = [a, b, c]

current_turn = 0
while True:
    if len(abc[0]) == 0 or len(abc[1]) == 0 or len(abc[2]) == 0:
        break
    next_turn = ord(abc[current_turn][0]) - ord('a')
    abc[current_turn] = abc[current_turn][1:]
    current_turn = next_turn

print(chr(current_turn + ord('A')))


Fixed code:
a = input()
b = input()
c = input()
abc = [a, b, c]

current_turn = 0
while True:
    if len(abc[current_turn]) == 0:
        break
    next_turn = ord(abc[current_turn][0]) - ord('a')
    abc[current_turn] = abc[current_turn][1:]
    current_turn = next_turn
    # print(abc[0], abc[1], abc[2])

print(chr(current_turn + ord('A')))
Buggy code:
a=list(input())
b=list(input())
c=list(input())
t="a"
while a!=[] and b!=[] and c!=[]:
  if t=="a":
    t=a[0]
    del a[0]
  elif t=="b":
    t=b[0]
    del b[0]
  else:
    t=c[0]
    del c[0]
if a==[]:
  print("A")
elif b==[]:
  print("B")
else:
  print("C")

Fixed code:
a=list(input())
b=list(input())
c=list(input())
t="a"
a.append(0)
b.append(0)
c.append(0)
while a!=[] and b!=[] and c!=[]:
  if t=="a":
    t=a[0]
    del a[0]
  elif t=="b":
    t=b[0]
    del b[0]
  else:
    t=c[0]
    del c[0]
if a==[]:
  print("A")
elif b==[]:
  print("B")
else:
  print("C")
Buggy code:
S_A = [i for i in input()]
S_B = [i for i in input()]
S_C = [i for i in input()]
T = S_A
l = T.__len__()
while(l > 0):
    t = T.pop(0)
    if t == 'a':
        T = S_A
    elif t == 'b':
        T = S_B
    elif t == 'c':
        T = S_C
    l = T.__len__()
if 0 == S_A.__len__():
    print("A")
elif 0 == S_B.__len__():
    print("B")
else:
    print("C")


Fixed code:
S_A = [i for i in input()+'A']
S_B = [i for i in input()+'B']
S_C = [i for i in input()+'C']
T = S_A
l = T.__len__()
while(l > 1):
    t = T.pop(0)
    if t == 'a':
        T = S_A
    elif t == 'b':
        T = S_B
    elif t == 'c':
        T = S_C
    l = T.__len__()
print(T[0])
Buggy code:
a_card = list(input())
b_card = list(input())
c_card = list(input())

turn = 'a'
while True:
    if turn == 'a':
        turn = a_card.pop(0)
        print(a_card, b_card, c_card)
        if len(a_card) == 0:
            print('A')
            exit()
    elif turn == 'b':
        turn = b_card.pop(0)
        print(a_card, b_card, c_card)
        if len(a_card) == 0:
            print('B')
            exit()
    else:
        turn = c_card.pop(0)
        print(a_card, b_card, c_card)
        if len(a_card) == 0:
            print('C')
            exit()


Fixed code:
a_card = list(input())
b_card = list(input())
c_card = list(input())

turn = 'a'
while True:
    if turn == 'a':
        if len(a_card) == 0:
            print('A')
            exit()
        turn = a_card.pop(0)

    elif turn == 'b':
        if len(b_card) == 0:
            print('B')
            exit()
        turn = b_card.pop(0)

    else:
        if len(c_card) == 0:
            print('C')
            exit()
        turn = c_card.pop(0)
Buggy code:
Sa, Sb, Sc = open(0).read().split()
print(Sa, Sb,Sc)
numSa = len(Sa)
numSb = len(Sb)
numSc = len(Sc)
#print(numSa,numSb,numSc)
i=j=k=0
flgA = True
flgB = flgC = False
l=0
while(True):
    if flgA == True:
        #print("A",i)
        flgA = False
        if numSa-1==i:
            print("A")
            break
        if Sa[i] == "a":
            flgA = True
        elif Sa[i] == "b":
            flgB = True
        else:
            flgC = True
        i+=1
    elif flgB == True:
        #print("B",j)
        flgB = False
        if numSb-1==j:
            print("B")
            break
        if Sb[j] == "a":
            flgA = True
        elif Sb[j] == "b":
            flgB = True
        else:
            flgC = True
        j+=1
    elif flgC == True:
        #print("C",k)
        flgC = False
        if numSc-1==k:
            print("C")
            break
        if Sc[k] == "a":
            flgA = True
        elif Sc[k] == "b":
            flgB = True
        else:
            flgC = True
        k+=1
    else:
        pass

    #print(l,"::",Sa[i],i,Sb[j],j,Sc[k],k) 
    l+=1

Fixed code:
Sa, Sb, Sc = open(0).read().split()
# print(Sa, Sb,Sc)
numSa = len(Sa)
numSb = len(Sb)
numSc = len(Sc)
# print(numSa,numSb,numSc)
i=j=k=0
flgA = True
flgB = flgC = False
l=0
# noDebug = False
while(True):
    if flgA == True:
#         print("A",i)
        flgA = False
        if numSa==i:
             print("A")
#             noDebug = True
             break
        if Sa[i] == "a":
            flgA = True
        elif Sa[i] == "b":
            flgB = True
        else:
            flgC = True
        i+=1
    elif flgB == True:
#         print("B",j)
        flgB = False
        if numSb==j:
            print("B")
#             noDebug = True
            break
        if Sb[j] == "a":
            flgA = True
        elif Sb[j] == "b":
            flgB = True
        else:
            flgC = True
        j+=1
    elif flgC == True:
#         print("C",k)
        flgC = False
        if numSc==k:
            print("C")
#             noDebug = True
            break
        if Sc[k] == "a":
            flgA = True
        elif Sc[k] == "b":
            flgB = True
        else:
            flgC = True
        k+=1
    else:
        pass
#     if noDebug == False:
#         print(l)
#         print(l,"::",Sa[i],i,Sb[j],j,Sc[k],k) 
#     l+=1
Buggy code:

A, B, C = list(input() for i in range(3))

turn = "a"

while True:
    if turn == 'a':
        if len(A) != 0:
            turn = A.pop(0)
        else:
            print('A')
            break
    elif turn == 'b':
        if len(B) != 0:
            turn = B.pop(0)
        else:
            print('B')
            break
    elif turn == 'c':
        if len(C) != 0:
            turn = C.pop(0)
        else:
            print('C')
            break

Fixed code:
A, B, C = [list(input()) for i in range(3)]


turn = "a"

while True:
    if turn == 'a':
        if len(A) != 0:
            turn = A.pop(0)
        else:
            print('A')
            break
    elif turn == 'b':
        if len(B) != 0:
            turn = B.pop(0)
        else:
            print('B')
            break
    elif turn == 'c':
        if len(C) != 0:
            turn = C.pop(0)
        else:
            print('C')
            break
Buggy code:
from collections import deque
S = [list(input()) for _ in range(3)]

SA = deque(S[0])
SB = deque(S[1])
SC = deque(S[2])

i = 'a'
ans = 'now playing'

while ans == 'now playing':
  if i == 'a':
    if SA == deque([]):
      ans = 'A'
    else:
      i = SA.popleft()
  elif i == 'b':
    if SB == deque([]):
      ans = 'B'
    else:
      i = SB.popleft()
  else:
    if SC == deque([]):
      ans = 'C'
    else:
      i = SC.popleft()

print(SA,SB,SC,ans)

Fixed code:
from collections import deque
S = [list(input()) for _ in range(3)]

SA = deque(S[0])
SB = deque(S[1])
SC = deque(S[2])

i = 'a'
ans = 'now playing'

while ans == 'now playing':
  if i == 'a':
    if SA == deque([]):
      ans = 'A'
    else:
      i = SA.popleft()
  elif i == 'b':
    if SB == deque([]):
      ans = 'B'
    else:
      i = SB.popleft()
  else:
    if SC == deque([]):
      ans = 'C'
    else:
      i = SC.popleft()

print(ans)
Buggy code:
n = A.pop(0)
while True:
  if n == 'a':
    if A == []:
      print('A')
      break
    n = A.pop(0)
  elif n == 'b':
    if B == []:
      print('B')
      break
    n = B.pop(0)
  else:
    if C == []:
      print('C')
      break
    n = C.pop(0)

Fixed code:
A = list(input())
B = list(input())
C = list(input())

n = A.pop(0)
while True:
  if n == 'a':
    if A == []:
      print('A')
      break
    n = A.pop(0)
  elif n == 'b':
    if B == []:
      print('B')
      break
    n = B.pop(0)
  else:
    if C == []:
      print('C')
      break
    n = C.pop(0)
Buggy code:
A = list(input())
B = list(input())
C = list(input())
next = A.pop(0)
while 1:
  if next == 'a':
    next = A.pop(0)
  elif next == 'b':
    next = B.pop(0)
  else:
    next = C.pop(0)
  if len(A) == 0:
    print("A")
    break
  elif len(B) == 0:
    print("B")
    break
  elif len(C) == 0:
    print("C")
    break
    
          

Fixed code:
A = list(input())
B = list(input())
C = list(input())
next = A.pop(0)
while 1:
  if next == 'a':
    if len(A) == 0:
      print("A")
      break
    next = A.pop(0)
  elif next == 'b':
    if len(B) == 0:
      print("B")
      break
    next = B.pop(0)
  else:
    if len(C) == 0:
      print("C")
      break
    next = C.pop(0)
Buggy code:
from collections import deque
A = deque(map(str, input()))
B = deque(map(str, input()))
C = deque(map(str, input()))
x = A.popleft()
for _ in range(10000000):
    if x == "a":
        if A:
            x = A.popleft()
        else:
            print("A")
            break
    elif x == "b":
        if B:
            x = B.popleft()
        else:
            print("B")
    else:
        if C:
            x = C.popleft()
        else:
            print("C")


Fixed code:
from collections import deque
A = deque(map(str, input()))
B = deque(map(str, input()))
C = deque(map(str, input()))
x = A.popleft()
for _ in range(10000000):
    if x == "a":
        if A:
            x = A.popleft()
        else:
            print("A")
            break
    elif x == "b":
        if B:
            x = B.popleft()
        else:
            print("B")
            break
    else:
        if C:
            x = C.popleft()
        else:
            print("C")
            break
Buggy code:
A = str(input())
B = str(input())
C = str(input())

turn = "A"
while True:
  if turn = "A":
    turn = A[0].upper()
    if len(A) == 1:
      print(A)
      break
    A = A[1:len(A)]
  if turn = "B":
    turn = B[0].upper()
    if len(B) == 1:
      print(B)
      break
    B = B[1:len(B)]
  if turn = "C":
    turn = C[0].upper()
    if len(C) == 1:
      print(C)
      break
    C = C[1:len(C)]

Fixed code:
A = str(input())
B = str(input())
C = str(input())

turn = "A"
while True:
  if turn == "A":
    if len(A) == 0:
      print(turn)
      break
    turn = A[0].upper()
    A = A[1:len(A)]
  elif turn == "B":
    if len(B) == 0:
      print(turn)
      break
    turn = B[0].upper()
    B = B[1:len(B)]
  else:
    if len(C) == 0:
      print(turn)
      break
    turn = C[0].upper()
    C = C[1:len(C)]
Buggy code:
#ABC045.A
s1 = input()
s2 = input()
s3 = input()

turn = s1[0]
s1 = s1[1:]

while True:
    if turn =='a':
        if not s1:
            winner = 'A'
            break
        else:
            turn == s1[0]
            s1 = s1[1:]
    elif turn =='b':
        if not s2:
            winner ='B'
            break
        else:
            turn == s2[0]
            s2 =s2[1:]
    elif turn =='c':
        if not s3:
            winner ='C'
            break
        else:
            turn ==s3[0]
            s3 = s3[1:]
print(winner)

Fixed code:
#ABC045.A
s1 = input()
s2 = input()
s3 = input()

turn = s1[0]
s1 = s1[1:]

while True:
    if turn =='a':
        if not s1:
            winner = 'A'
            break
        else:
            turn = s1[0]
            s1 = s1[1:]
    elif turn =='b':
        if not s2:
            winner ='B'
            break
        else:
            turn = s2[0]
            s2 =s2[1:]
    elif turn =='c':
        if not s3:
            winner ='C'
            break
        else:
            turn =s3[0]
            s3 = s3[1:]
print(winner)
Buggy code:
S = Sa
card = S.pop(0)
while True:
    if card == 'a':
        S = Sa
    if card == 'b':
        S = Sb
    if card == 'c':
        S = Sc
    try:
        card = S.pop(0)
    except:
        print(card.upper())
        break

Fixed code:
Sa = list(input())
Sb = list(input())
Sc = list(input())
card = Sa.pop(0)
while True:
    if card == 'a':
        S = Sa
    if card == 'b':
        S = Sb
    if card == 'c':
        S = Sc
    try:
        card = S.pop(0)
    except:
        print(card.upper())
        break
Buggy code:
A = input()
B = input()
C = input()
now = 'a'
na = 0
nb = 0
nc = 0
for _ in range(303):
    print(now, na, nb, nc)
    if now == 'a':
        if na == len(A):
            print('A')
            break
        now = A[na]
        na += 1
    elif now == 'b':
        if nb == len(B):
            print('B')
            break
        now = B[nb]
        nb += 1
    else:
        if nc == len(C):
            print('C')
            break
        now = C[nc]
        nc += 1

Fixed code:
A = input()
B = input()
C = input()
now = 'a'
na = 0
nb = 0
nc = 0
for _ in range(303):
    if now == 'a':
        if na == len(A):
            print('A')
            break
        now = A[na]
        na += 1
    elif now == 'b':
        if nb == len(B):
            print('B')
            break
        now = B[nb]
        nb += 1
    else:
        if nc == len(C):
            print('C')
            break
        now = C[nc]
        nc += 1