Problem p03998 (python)

Fixed submission:
# 入力
SA=list(input())
SB=list(input())
SC=list(input())

# 次に捨てる人（初期値は'A')
x='a'

while True:
  if x=='a':
    # リストの要素が0ならば終了する
    if len(SA)==0:
      print('A')
      exit()

    # 先頭要素を除去してxに代入
    x=SA[0]
    SA.remove(x)
  elif x=='b':
    # リストの要素が0ならば終了する
    if len(SB)==0:
      print('B')
      exit()

    # 先頭要素を除去してxに代入
    x=SB[0]
    SB.remove(x)
  else:
    # リストの要素が0ならば終了する
    if len(SC)==0:
      print('C')
      exit()

    # 先頭要素を除去してxに代入
    x=SC[0]
    SC.remove(x)

Buggy submission (verdict: Runtime Error):
a_list = list(input())
b_list = list(input())
c_list = list(input())

a_turn = True
b_turn = False
c_turn = False

max_battle = len(a_list) + len(b_list) + len(c_list)

for i in range(max_battle):
    if(a_turn):
        a_list.pop(0)
        if(len(a_list) == 0):
            print("A")
            exit() 
        else:
            if(a_list[0] == 'b'):
                a_turn = False
                b_turn = True 
            elif(a_list[0] == 'c'):
                a_turn = False
                c_turn = True  
    elif(b_turn):
        a_list.pop(0)
        if(len(b_list) == 0):
            print("B")
            exit() 
        else:
            if(b_list[0] == 'a'):
                b_turn = False
                a_turn = True 
            elif(b_list[0] == 'c'):
                b_turn = False
                c_turn = True  
    elif(c_turn):
        c_list.pop(0)
        if(len(c_list) == 0):
            print("C")
            exit() 
        else:
            if(c_list[0] == 'a'):
                c_turn = False
                a_turn = True 
            elif(a_list[0] == 'b'):
                c_turn = False
                b_turn = True

Buggy submission (verdict: Runtime Error):
a_list = list(input())
b_list = list(input())
c_list = list(input())

a_turn = True
b_turn = False
c_turn = False

max_battle = len(a_list) + len(b_list) + len(c_list)

for i in range(max_battle):
    if(a_turn):
        a_list.pop(0)
        if(len(a_list) == 0):
            print("a")
            exit() 
        else:
            if(a_list[0] == 'b'):
                a_turn = False
                b_turn = True 
            elif(a_list[0] == 'c'):
                a_turn = False
                c_turn = True  
    elif(b_turn):
        a_list.pop(0)
        if(len(b_list) == 0):
            print("b")
            exit() 
        else:
            if(b_list[0] == 'a'):
                b_turn = False
                a_turn = True 
            elif(b_list[0] == 'c'):
                b_turn = False
                c_turn = True  
    elif(c_turn):
        c_list.pop(0)
        if(len(c_list) == 0):
            print("c")
            exit() 
        else:
            if(c_list[0] == 'a'):
                c_turn = False
                a_turn = True 
            elif(a_list[0] == 'b'):
                c_turn = False
                b_turn = True

Buggy submission (verdict: Runtime Error):
a_list = list(input())
b_list = list(input())
c_list = list(input())

a_turn = True
b_turn = False
c_turn = False

max_battle = len(a_list) + len(b_list) + len(c_list)

for i in range(max_battle):
    if(a_turn):
        a_list.pop(0)
        if(len(a_list) == 0):
            print("a")
            exit() 
        else:
           if(a_list[0] == 'b'):
                a_turn = False
                b_turn = True 
            elif(a_list[0] == 'c'):
                a_turn = False
                c_turn = True  
    elif(b_turn):
        a_list.pop(0)
        if(len(b_list) == 0):
            print("b")
            exit() 
        else:
            if(b_list[0] == 'a'):
                b_turn = False
                a_turn = True 
            elif(b_list[0] == 'c'):
                b_turn = False
                c_turn = True  
    elif(c_turn):
        c_list.pop(0)
        if(len(c_list) == 0):
           print("c")
           exit() 
        else:
            if(c_list[0] == 'a'):
                c_turn = False
                a_turn = True 
            elif(a_list[0] == 'b'):
                c_turn = False
                b_turn = True