Problem:


Drawing Lots

Let's play Amidakuji. 

In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.

In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom.

Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.

Input

w
n
a1,b1
a2,b2
.
.
an,bn

w (w ≤ 30) is the number of vertical lines. n (n ≤ 30) is the number of horizontal lines. A pair of two integers ai and bi delimited by a comma represents the i-th horizontal line.

Output

The number which should be under the 1st (leftmost) vertical line

The number which should be under the 2nd vertical line

:

The number which should be under the w-th vertical line

Sample Input

5
4
2,4
3,5
1,2
3,4

Output for the Sample Input

4
1
2
5
3

Try it.
-->



Sample input:
5
4
2,4
3,5
1,2
3,4


Sample output:
4
1
2
5
3

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

wlst = [i for i in range(1, w+1)]
for i in range(n):
    inputlst = list(map(int, input().split(',')))
    a, b = inputlst[0]-1, inputlst[1]-1
    wlst[a], wlst[b] = wlst[b], wlst[a]

for i in wlst:
    print(i)

Submission status: Accepted

Solution code:
W = int(input())
N = int(input())
*R, = range(1, W+1)
for i in range(N):
    a, b = map(int, input().split(","))
    R[a-1], R[b-1] = R[b-1], R[a-1]
print(*R, sep='\n')

Submission status: Accepted

Solution code:
w = int(input())
s = [i for i in range(1,w+1)]
n = int(input())
for i in range(n):
    a = list(map(int, input().split(',')))
    s[a[0]-1],s[a[1]-1] = s[a[1]-1],s[a[0]-1]

for i in s:
    print(i)

Submission status: Accepted

Solution code:
numList = []
for i in range(int(input())):
    numList.append(i + 1)

for i in range(int(input())):
    a, b = list(map(int, input().split(',')))
    a, b = a - 1, b - 1
    tmp = numList[a]
    numList[a] = numList[b]
    numList[b] = tmp

for num in numList:
    print(num)

Submission status: Accepted

Solution code:
table = [(0,0)] * 31
dp = [0] * 31

w = int(input())
h = int(input())
for i in range(1,h + 1):
    a,b = (int(_) for _ in input().split(","))
    table[i] = (a,b)

# あみだくじ
for i in range(1,w + 1):
    dest = i
    for j in range(1,h + 1):
        if table[j][0] == dest:
            dest = table[j][1]
        elif table[j][1] == dest:
            dest = table[j][0]
    dp[dest] = i    
    
for i in range(1,w + 1):
    print(dp[i])

Submission status: Accepted

Solution code:
W = int(input())
N = int(input())

C = [[-1 for j in range(W)] for i in range(N)]

for i in range(N):
    a, b = map(lambda x:int(x) - 1, input().split(','))
    C[i][a] = b
    C[i][b] = a

A = [-1] * W
for n in range(W):
    j = n
    for i in range(N):
        if C[i][j] >= 0:
            j = C[i][j]
    A[j] = n + 1

for v in A:
    print(v)

Submission status: Accepted

Solution code:
W = int(input());#list(map(int, input().split()))
N = int(input());#list(map(int, input().split()))

field=[[-1 for i in range(W)] for j in range(N)]

for i in range(N):
	a,b=list(map(int, input().split(',')))
	field[i][a-1]=b-1;
	field[i][b-1]=a-1;

result=[0 for i in range(W)];
for i in range(W):
	now=i;
	for j in range(N):
		if(field[j][now]!=-1):
			now=field[j][now];
	result[now]=i+1;

for i in result:
	print(i);

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
lv = [i for i in range(1, w+1)]

for _ in range(n):
    a, b = list(map(int, input().split(",")))
    tmp = lv[a - 1]
    lv[a - 1] = lv[b - 1]
    lv[b - 1] = tmp

for v in lv:
    print(v)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
p = list(range(n+1))
for i in range(m):
    a, b = map(int, input().split(","))
    p[a], p[b] = p[b], p[a]

for v in p[1:]:
    print(v)

Submission status: Accepted

Solution code:
n = int(input())
h = int(input())
arr = list(range(1, n + 1))
for _ in range(h):
    a, b = map(int, input().split(','))
    arr[a - 1], arr[b - 1] = arr[b - 1], arr[a - 1]
for ai in arr:
    print(ai)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

A = list()
B = list()

S = [i for i in range(1, w + 1)]
G = [0 for i in range(w)]

for i in range(n) :
    a , b = map(int, input().split(","))
    A.append(a)
    B.append(b)
    
for i in range(1, w + 1) :
    g = i
    for j in range(n) :
        if(A[j] == g) :
            g = B[j]
        elif(B[j] == g) :
            g = A[j]
        else :
            pass
    G[g - 1] = i
    
for i in range(w) :
    print(G[i])

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

L = list(range(1,w+1))

for i in range(n):
    a, b = [int(x)-1 for x in input().split(",")]
    L[a], L[b] = L[b], L[a]

for i in L:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
a = range(w)
a = list(a)
for i in range(n):
    p, q = map(int, input().split(","))
    t = a[p - 1]
    a[p - 1] = a[q - 1]
    a[q - 1] = t
for each in a:
    print(each + 1)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

c = list(range(0, w+1))
for i in range(n):
    a, b = map(int, input().split(','))
    c[a], c[b] = c[b], c[a]

for i in range(1, w + 1):
    print(c[i])

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
l = list(range(1,w+1))

for i in range(n):
  a, b = map(int, input().split(","))
  l[a-1], l[b-1] = l[b-1], l[a-1]
  
for i in range(w):
    print(l[i])

Submission status: Accepted

Solution code:
s = [i + 1 for i in range(int(input()))]
n = int(input())
for _ in range(n):
   a , b = map(int, input().split(","))
   s[a-1], s[b-1] = s[b-1], s[a-1]
for i in s:
   print(i)

Submission status: Accepted

Solution code:
a=[int(i+1) for i in range(int(input()))]
for i in range(int(input())):
    b,c=map(int,input().split(','))
    a[b-1],a[c-1]=a[c-1],a[b-1]
for i in a:print(i)

Submission status: Accepted

Solution code:
w = int(input())
s = [i for i in range(w+1)]
n = int(input())
for i in range(n):
    a = list(map(int,input().split(",")))
    s[a[0]], s[a[1]] = s[a[1]], s[a[0]]
for i in range(1, w+1):
    print(s[i])

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():

    W = int(input())
    N = int(input())
    AB = [[int(x)-1 for x in input().split(',')] for i in range(N)]
    
    ans = list(range(1, W+1))

    for ab in AB:
        ans[ab[0]], ans[ab[1]] = ans[ab[1]], ans[ab[0]]

    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	line = int(input())
	A = [i+1 for i in range(line)]
	n = int(input())

	for _ in range(n):
		j,k = map(int,input().split(","))

		A[j-1],A[k-1] = A[k-1],A[j-1]

	for i in range(line):
		print(A[i])

Submission status: Accepted

Solution code:
a = []
b = []
numbers_s = []
numbers_g = []

w = int(input())
n = int(input())

for i in range(0, n):
    temp_a, temp_b = input().split(',')
    a.append(int(temp_a))
    b.append(int(temp_b))

for i in range(0, w):
    numbers_s.append(i+1)
    numbers_g.append(0)

for i in range(0, w):

    temp_idx = i+1

    for j in range(0, n):
        if temp_idx == a[j]: temp_idx = b[j]
        elif temp_idx == b[j]: temp_idx = a[j]

    numbers_g[temp_idx - 1] = i+1

for i in range(0, len(numbers_g)):
    print(numbers_g[i])

Submission status: Accepted

Solution code:
w = int(input())
c = [i for i in range(1, w + 1)]
n = int(input())
for i in range(n):
  a, b = map(int, input().split(","))
  r = c[a - 1]
  c[a - 1] = c[b - 1]
  c[b - 1] = r
for i in range(w):
  print(c[i])

Submission status: Accepted

Solution code:
def amida():
    line_number=int(input())
    line=[]
    for j in range(1,line_number+1):
        line.append(j)
    yoko=int(input())
    for i in range(yoko):
        a,b=map(int,input().split(","))
        line[a-1],line[b-1]=line[b-1],line[a-1]
    return line
while True:
    try:
        ans=amida()
        for i in range(int(len(ans))):
            print(ans[i])
        break
    except:break

Submission status: Accepted

Solution code:
w = [i for i in range(int(input()))]
n = int(input())

for i in range(n):
  a, b = map(int, input().split(","))
  w[a-1], w[b-1] = w[b-1], w[a-1]

for i in range(len(w)):
  print(w[i]+1)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
l = [i for i in range(1, w+1)]

for i in range(n):
    (a,b) = map(lambda x:int(x)-1, input().strip().split(","))
    (l[a],l[b]) = (l[b],l[a])

print(*l,sep="\n")

Submission status: Accepted

Solution code:
w=int(input())
n=int(input())
S=[i for i in range(1,w+1)]
for i in range(n):
    a,b = [int(i) for i in input().split(",")]
    tmp=S[a-1]
    S[a-1]=S[b-1]
    S[b-1]=tmp
for i in S:
    print(i)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    w = int(input())
    n = int(input())
    lst = []
    anslst = [0 for i in range(w)]
    for i in range(n):
        a, b = map(int, input().split(','))
        lst.append((a,b))
    for i in range(1,w+1):
        x = i 
        for (f,s) in lst:
            if f == x:
                x = s
            elif s == x:
                x = f
        anslst[x-1] = i
    for n in anslst:
        print(n)

Submission status: Accepted

Solution code:
#import math

w = int(input())
n = int(input())
field = [i for i in range(w+1)]
for i in range(n):
    a,b = map(int,input().split(","))
    field[a],field[b] = field[b],field[a]

for i in range(1,w+1):
    print(field[i])

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
l = list(range(1, w+1))
for i in range(n):
  a, b = map(int, input().split(','))
  a -= 1
  b -= 1
  l[a], l[b] = l[b], l[a]
for i in l:
  print(i)

Submission status: Accepted

Solution code:
w=int(input())
num=[i+1 for i in range(w)]
n=int(input())
for i in range(n):
	data=list(map(int,input().split(",")))
	a=num[data[0]-1]
	num[data[0]-1]=num[data[1]-1]
	num[data[1]-1]=a
for i in range(w):
	if i==w-1:
		print(num[i],end="\n")
	else:
		print(num[i])

Submission status: Accepted

Solution code:
w=int(input())
n=int(input())
lst=[i+1 for i in range(w)]
for i in range(n):
    x,y=map(int,input().split(","))
    lst[x-1],lst[y-1]=lst[y-1],lst[x-1]
for i in lst:print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

def swap(nlist,i,j):
    temp = nlist[i-1]
    nlist[i-1] = nlist[j-1]
    nlist[j-1] = temp
    return nlist

nlist = [i+1 for i in range(w)]
for i in range(n):
    i,j = [int(a) for a in input().split(',')]
    swap(nlist,i,j)
for i in nlist:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

amida = [i for i in range(1, w + 1)]
for _ in range(n):
    a, b = [int(i) - 1 for i in input().split(",")]
    amida[a], amida[b] = amida[b], amida[a]

for x in amida:
    print(x)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

alist = []
blist = []
for _ in range(n):
    a, b = map(int, input().split(","))
    alist.append(a)
    blist.append(b)

ans = [0] * w

for i in range(1, w+1):
    position = i
    for a, b in zip(alist, blist):
        if a == position:
            position = b
        elif b == position:
            position = a

    ans[position-1] = i

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
w = int(input())    # 縦線
n = int(input())    # 横線
combine = [list(map(int, input().split(","))) for _ in range(n)]   # 横棒の終始
answer = list(range(1, w+1))    # 回答

# 終始入れ替え
for com in combine:
    x, y = com
    answer[x-1], answer[y-1] = answer[y-1], answer[x-1]

# 出力（改行あり）
print('\n'.join(map(str, answer)))

Submission status: Accepted

Solution code:
w = int(input())
wa = list(range(w+1))
n = int(input())
for _ in range(n):
    a,b = map(int, input().split(","))
    wa[a],wa[b] = wa[b],wa[a]
for s in wa[1:]:
    print(s)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
kuji = [i+1 for i in range(w)]
for _ in range(n):
    a, b = map(int, input().split(','))
    kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1]
print(*kuji, sep="\n")

Submission status: Accepted

Solution code:
w = int(input())
bs = [ x+1 for x in range(w)]
n = int(input())

for i in range(n):
  a, b = map(lambda x:int(x)-1, input().split(','))
  bs[a], bs[b] = bs[b], bs[a]

[print(b) for b in bs]

Submission status: Accepted

Solution code:
ans=list(range(1,int(input())+1))
for i in range(int(input())):
    a,b=map(lambda x: int(x)-1,input().split(","))
    ans[a],ans[b]=ans[b],ans[a]
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
amida = [i+1 for i in range(w)]
for i in range(n):
    a,b = map(int,input().split(","))
    v = amida[a-1]
    amida[a-1] = amida[b-1]
    amida[b-1] = v
for i in amida:
    print(i)

Submission status: Accepted

Solution code:
# Drawing Lots
W = [i+1 for i in range(int(input()))]
n = int(input())
for _ in range(n):
    a,b = map(int, input().split(','))
    W[a-1], W[b-1] = W[b-1], W[a-1]
for w in W: print(w)

Submission status: Runtime Error

Solution code:
while True:
    w = int(raw_input())
    n = int(raw_input())
    ans = []
    ans = [j for j in range(1,w+1)]
    for k in range(n):
        a,b = map(int,(raw_input().split(",")))
        ans[a-1],ans[b-1] = ans[b-1],ans[a-1]
    for item in ans:
        print item

Submission status: Runtime Error

Solution code:
l=xrange(1,input()+1)
for a,b in[map(int,raw_input().split(","))for i in xrange(input())]:l[a-1],l[b-1]=l[b-1],l[a-1]
for i in l:print i

Submission status: Runtime Error

Solution code:
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()

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import Counter

ww = raw_input()
nn = raw_input()
n = int(nn)
w = int(ww)
kuji = []
for i in range(w):
    kuji.append(i+1)
for i in range(n):
    l = raw_input()
    a = int(l[0])
    b = int(l[2])
    temp = kuji[a-1]
    kuji[a-1] = kuji[b-1]
    kuji[b-1] = temp
for i in range(w):
    print kuji[i]

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import Counter

ww = raw_input()
nn = raw_input()
n = int(nn)
w = int(ww)
kuji = []
for i in range(w):
    kuji.append(i+1)
while n > 0:
    l = raw_input()
    a = int(l[0])
    b = int(l[2])
    temp = kuji[a-1]
    kuji[a-1] = kuji[b-1]
    kuji[b-1] = temp
    n -= 1

for i in range(w):
    print kuji[i]

Submission status: Runtime Error

Solution code:

import sys
import math
from collections import Counter

ww = raw_input()
nn = raw_input()
n = int(nn)
w = int(ww)
k = []
for i in range(w):
    k.append(i+1)
while 1:
    if n == 0:
        break
    l = raw_input()
    a = int(l[0])
    b = int(l[2])
    temp = k[a-1]
    k[a-1] = k[b-1]
    k[b-1] = temp
    n -= 1

for i in range(w):
    print k[i]

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import Counter

w = input()
n = input()
k = []
for i in range(w+1):
    k.append(i)
for i in range(n):
    l = raw_input()
    a = int(l[0])
    b = int(l[2])
    temp = k[a]
    k[a] = k[b]
    k[b] = temp

for i in range(w):
    print k[i+1]

Submission status: Runtime Error

Solution code:

import sys
import math

w = input()
n = input()
k = []
for i in range(w+1):
    k.append(i)
for i in range(n):
    l = raw_input()
    a = int(l[0])
    b = int(l[2])
    temp = k[a]
    k[a] = k[b]
    k[b] = temp

for i in range(w):
    print k[i+1]

Submission status: Runtime Error

Solution code:


w = int(input())
n = int(input())
k = []
for i in range(w+1):
    k.append(i)
for j in range(n):
    l = raw_input()
    a = int(l[0])
    b = int(l[2])
    temp = k[a]
    k[a] = k[b]
    k[b] = temp

for l in range(w):
    print k[l+1]

Submission status: Runtime Error

Solution code:
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()

Submission status: Runtime Error

Solution code:
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()

Submission status: Runtime Error

Solution code:
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()

Submission status: Runtime Error

Solution code:
w = int(raw_input())
n = int(raw_input())
l = [i for i in range(1,w+1)]
while n > 0:
  a,b = map(int,raw_input().split(','))
  l[a-1],l[b-1] = l[b-1],l[a-1]
  n -= 1
for i in l:
  print(i)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d,e=map(int,raw_input().split())
    c[d],c[e]=c[e],c[d]
[print(i) for i in c]

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d,e=map(int,raw_input().split())
    c[d],c[e]=c[e],c[d]
for i in c:print(i)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d=map(int,raw_input().split())
    c[d[0]],c[d[-1]]=c[d[-1]],c[d[0]]
for i in c:print(i)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d=str(raw_input())
    c[int(d[0]-1)],c[int(d[-1]-1)]=c[int(d[-1]-1)],c[int(d[0]-1)]
for i in c:print(i)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d=str(raw_input())
    d,e=int(d[0]-1),int(d[2]-1)
    c[d],c[e]=c[e],c[d)
for i in c:print(i)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d=str(raw_input())
    d,e=int(d[0]-1),int(d[2]-1)
    c[d],c[e]=c[e],c[d])
for i in c:print(i)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d,e=map(int,raw_input().split())
    c[d],c[e]=c[e],c[d])
for i in c:print(i)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def solve(w, n):
    l = [i for i in range(1, w+1)]
    for _ in range(n):
        a, b = map(int, input().split(','))
        l[a], l[b] = l[b], l[a]

    print(*l, sep='\n')

if __name__ == '__main__':
    w = int(input())
    n = int(input())
    solve(w, n)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def solve():
    w = int(input())
    n = int(input())
    l = [i for i in range(1, w+1)]

    for _ in range(n):
        a, b = map(int, input().split(','))
        l[a], l[b] = l[b], l[a]

    print(*l, sep='\n')

solve()

Submission status: Runtime Error

Solution code:
def swap(a, b, x):
    if x <> a and x <> b:
        return x
    elif x == a:
        return b
    elif x == b:
        return a

w = raw_input()
n = raw_input()

result = range(1, w+1)

for i in range(n):
    a, b = map(lambda x: int(x), raw_input().split(',')
    result = [ swap(a, b, x) for x in result ]

for x in result:
    print x

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-

import sys

w = int(input())
n = int(input())

array = []
count = 0
for i in sys.stdin:
    array.append(i)
    count += 1
    if count == n:
        break

a, b = [0]*n, [0]*n
for i in range(n):
    s = array[i]
    a[i], b[i] = s[0], s[2]
    a[i], b[i] = int(a[i]), int(b[i])

lines = []
k = 0
for i in range(w):
    lines.append(k)
    k += 1 

for i in range(n):
    tmp1 = lines[a[i]-1]
    tmp2 = lines[b[i]-1]
    lines[a[i]-1] = tmp2
    lines[b[i]-1] = tmp1

for i in range(len(lines)):
    print(lines[i]+1)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import sys

w = int(input())
n = int(input())

array = []
count = 0
for i in sys.stdin:
    array.append(i)
    count += 1
    if count == n:
        break

a, b = [0]*n, [0]*n
for i in range(n):
    s = array[i]
    a[i], b[i] = s[0], s[2]
    a[i], b[i] = int(a[i]), int(b[i])

lines = []
k = 0
for i in range(w):
    lines.append(k)
    k += 1 

for i in range(n):
    tmp1 = lines[a[i]-1]
    tmp2 = lines[b[i]-1]
    lines[a[i]-1] = tmp2
    lines[b[i]-1] = tmp1

for i in range(len(lines)):
    print(lines[i]+1)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import sys

w = int(input())
n = int(input())

array = []
for i in range(n):
    array.append(input())

a, b = [0]*n, [0]*n
for i in range(n):
    s = array[i]
    a[i], b[i] = s[0], s[1]
    a[i], b[i] = int(a[i]), int(b[i])

lines = []
k = 0
for i in range(w):
    lines.append(k)
    k += 1 

for i in range(n):
    tmp1 = lines[a[i]-1]
    tmp2 = lines[b[i]-1]
    lines[a[i]-1] = tmp2
    lines[b[i]-1] = tmp1

for i in range(len(lines)):
    print(lines[i]+1)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import sys

w = int(input())
n = int(input())

array = [0]*n
for i in range(n):
    array[i] = input()

a, b = [0]*n, [0]*n
for i in range(n):
    s = array[i]
    a[i], b[i] = s[0], s[1]
    a[i], b[i] = int(a[i]), int(b[i])

lines = []
k = 0
for i in range(w):
    lines.append(k)
    k += 1 

for i in range(n):
    tmp1 = lines[a[i]-1]
    tmp2 = lines[b[i]-1]
    lines[a[i]-1] = tmp2
    lines[b[i]-1] = tmp1

for i in range(len(lines)):
    print(lines[i]+1)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import sys

w = int(input())
n = int(input())

array = []
for i in range(n):
    array.append(input())

a, b = [], []
for i in range(n):
    s = array[i]
    a.append(s[0])
    b.append(s[1])
    a[i], b[i] = int(a[i]), int(b[i])

lines = []
k = 0
for i in range(w):
    lines.append(k)
    k += 1 

for i in range(n):
    tmp1 = lines[a[i]-1]
    tmp2 = lines[b[i]-1]
    lines[a[i]-1] = tmp2
    lines[b[i]-1] = tmp1

for i in range(len(lines)):
    print(lines[i]+1)

Submission status: Runtime Error

Solution code:
w = int(input())
n = int(input())
nums = list(range(w + 1))
for i in range(n):
    s = list(map(int, input().split(", ")))
    nums[s[0]], nums[s[1]] = nums[s[1]], nums[s[0]]
for j in range(w):
    print(nums[j + 1])

Submission status: Runtime Error

Solution code:
w = int(input())
nums = list(range(w + 1))
for _ in range(int(input())):
    a, b = list(map(int, input().split(", ")))
    nums[a], nums[b] = nums[b], nums[a]
for i in range(w):
    print(nums[i + 1])

Submission status: Runtime Error

Solution code:
w = int(input())
nums = list(range(w + 1))
for _ in range(int(input())):
    a, b = map(int, input().split(", "))
    nums[a], nums[b] = nums[b], nums[a]
for x in nums[1:]:
    print(x)

Submission status: Runtime Error

Solution code:
w = int(input())
n = int(input())
nums = list(range(w + 1))
for _ in range(n):
    a, b = map(int, input().split(", "))
    nums[a], nums[b] = nums[b], nums[a]
for x in nums[1:]:
    print(x)

Submission status: Runtime Error

Solution code:
w = int(input())
n = int(input())
l = list(range(1,w+1))
for i in range(n):
	a,b = map(int,input().split(','))
	a -= 1
	b - = 1
	l[a],l[b] = l[b],l[a]
for x in l:
	print(x)

Submission status: Runtime Error

Solution code:
a=[i+1 for i in range(int(input()))]
for _ in[0]*int(input()):
 s,t=map(int,input().split(','))
 a[s],a[t]=a[t],a[s]
for s in a:print(s+1)

Submission status: Runtime Error

Solution code:
a=list(range(int(input())+1))
for _ in[0]*int(input()):s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s]
for s in a:s*print(s)

Submission status: Runtime Error

Solution code:
import  math
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split()
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Runtime Error

Solution code:
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split()
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Runtime Error

Solution code:
tate =int(input());
yoko=int(input());
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split()
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Runtime Error

Solution code:
tate =int(input());
yoko=int(input());
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split();
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Runtime Error

Solution code:
tate =int(input());
yoko=int(input());
arr = [i+1 for i in range(tate)]
for j in range(yoko):
 rep1,rep2=input().split();
 rep1=int(rep1)-1
 rep2=int(rep2)-1
 arr[rep1],arr[rep2] = arr[rep2],arr[rep1]
for k in range(tate):
 print(arr[k])

Submission status: Runtime Error

Solution code:
tate =int(raw_input())
yoko=int(raw_input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=raw_input().split();
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Runtime Error

Solution code:
import math
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split();
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Runtime Error

Solution code:
import math
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split();
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k] )

Submission status: Runtime Error

Solution code:
w=input()
l=[i+1 for i in range(w)]
n=input()
for _ in range(n):
    a,b=[int(i)-1 for i in input().split(",")]
    t=l[a]
    l[a]=l[b]
    l[b]=t
for i in w:
    print(i)

Submission status: Runtime Error

Solution code:
w=int(input())
l=[i+1 for i in range(w)]
n=int(input())
for _ in range(n):
    a,b=[int(i)-1 for i in input().split(",")]
    t=l[a]
    l[a]=l[b]
    l[b]=t
for i in w:
    print(i)

Submission status: Runtime Error

Solution code:
w = int(input())
n = int(input())
nums = [1, 2, 3, 4, 5]
ab = []
for i in range(n):
    a, b = map(int, input().split(','))
    nums[a-1], nums[b-1] = nums[b-1], nums[a-1]
for i in nums:
    print(i)

Submission status: Runtime Error

Solution code:
w = int(input())
n = int(input())

amida = []

for i in range(0,w+1):
    amida.append(i)
    
for i in range(n):
    ai,bi = map(int,input().split())
    aa = amida[ai]
    bb = amida[bi]
    amida[ai] = bb
    amida[bi] = aa
    
for i in range(1,w+1):
    print(w[i])