Buggy python submission (verdict: Runtime Error):
def play():
    result_dic = {}    
    for i in range(tate):
        depart = i+1
        arrival = drawing_lots[depart][0]
        arrival = aaa(depart, arrival)
        result_dic[arrival] = depart
    
    for k in sorted(result_dic):
        print(result_dic[k])

def aaa(depart, arrival):
    offset = 0
    for point in drawing_lots[arrival]:
        if point == depart:
            break
        offset += 1
    
    if offset+1 <= len(drawing_lots[arrival])-1:
        depart = arrival
        arrival = drawing_lots[arrival][offset+1]
        return aaa(depart, arrival)
    else:
        return arrival
        
tate = int(raw_input())
yoko = int(raw_input())

drawing_lots = {}
for num in range(tate):
    drawing_lots[num+1] = []
    
for i in range(yoko):
    horizontal_line = raw_input().split(',')
    left_num = int(horizontal_line[0])
    right_num = int(horizontal_line[1])
    drawing_lots[left_num].append(right_num)
    drawing_lots[right_num].append(left_num)

play()

Fixed submission:
ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a

Buggy python submission (verdict: Runtime Error):
def f1(x, y):
    if not x in data:
        data[x] = [y]
    else:
        data[x].append(y)
        
def f2():
    for i in range(1, w+1):
        f3(data[i][0], i, i)
    else:
        for a in ans:
            print a
        
def f3(a, b, c):
    for i, num in enumerate(data[a]):
        if num == b:
            if i+1 < len(data[a]):
                return f3(data[a][i+1], a, c)
            else:
                ans[a-1] = c
                break
        
w = int(raw_input())
n = int(raw_input())
ans = [0 for i in range(1, w+1)]
data = {}
for i in range(n):
    a, b = map(int, raw_input().split(','))
    f1(a, b)
    f1(b, a)
else:
    f2()

Fixed submission:
ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a

Buggy python submission (verdict: Runtime Error):
def f1(x, y):
    if not x in data:
        data[x] = [y]
    else:
        data[x].append(y)
        
def f2():
    for i in range(1, w+1):
        f3(data[i][0], i, i)
    else:
        for a in ans:
            print a
        
def f3(a, b, c):
    for i, num in enumerate(data[a]):
        if num == b:
            if i+1 < len(data[a]):
                return f3(data[a][i+1], a, c)
            else:
                ans[a-1] = c
                break
        
w = int(raw_input())
n = int(raw_input())
ans = [0 for i in range(w)]
data = {}
for i in range(n):
    a, b = map(int, raw_input().split(','))
    f1(a, b)
    f1(b, a)
else:
    f2()

Fixed submission:
ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a

Buggy python submission (verdict: Runtime Error):
def play():
    result_dic = {}    
    for i in range(tate):
        depart = i+1
        arrival = drawing_lots[depart][0]
        arrival = aaa(depart, arrival)
        result_dic[arrival] = depart
    
    for k in sorted(result_dic):
        print(result_dic[k])

def aaa(depart, arrival):
    offset = 0
    for offset, point in enumerate(drawing_lots[arrival]):
        if point == depart:
            break
    
    if offset+1 <= len(drawing_lots[arrival])-1:
        depart = arrival
        arrival = drawing_lots[arrival][offset+1]
        return aaa(depart, arrival)
    else:
        return arrival
        
tate = int(raw_input())
yoko = int(raw_input())

drawing_lots = {}
for num in range(tate):
    drawing_lots[num+1] = []
    
for i in range(yoko):
    horizontal_line = raw_input().split(',')
    left_num = int(horizontal_line[0])
    right_num = int(horizontal_line[1])
    drawing_lots[left_num].append(right_num)
    drawing_lots[right_num].append(left_num)

play()

Fixed submission:
ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a