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  a 1 , b 1  a 2 , b 2 .
. a n , b n   w ( w ≤ 30) is the number of vertical lines. n ( n ≤ 30) is the number of horizontal lines. A pair of two integers a i and b i 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

Solution (Python):
def run():
    w = [i + 1 for i in range(int(input()))]
    n = int(input())
    for _ in range(n):
        s1, s2 = list(map(int, input().split(',')))
        w[s1-1], w[s2-1] = w[s2-1], w[s1-1]
    print('\n'.join([str(_w) for _w in w]))

if __name__ == '__main__':
    run()

Solution (Python):
import sys

n = int(sys.stdin.readline())
sys.stdin.readline()
l = range(1, n+1)

for line in sys.stdin:
  a,b = map(int, line.strip().split(','))
  l[a-1], l[b-1] = l[b-1], l[a-1]

for x in l:
  print x

Solution (Python):



import sys

num_v = input()
num_h = input()
lis = range(num_v+1)
for s in sys.stdin:
  d = map(int , s.split(",") )
  lis[d[0]], lis[d[1]] = lis[d[1]], lis[d[0]]
for e in lis[1:]:
  print e

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

lis=[i+1 for i in range(w)]

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

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

Solution (Python):
import sys
f = sys.stdin
w = int(f.readline())
lots = [i + 1for i in range(w)]


n = int(f.readline())
for _ in range(n):
    a, b = map(int , f.readline().split(','))
    lots[a - 1], lots[b - 1] = lots[b - 1], lots[a - 1]

for i in lots:
    print(i)

Solution (Python):
while True:
    try:
        w = int(raw_input())
        n = int(raw_input())
        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
    except EOFError:
        break

Solution (Python):






s=[]
W=int(input())
n=int(input())
for i in range(W):
    s.append(i+1)

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)

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

Solution (Python):
w=int(raw_input())

number = range(1,w+1)
for i in xrange(input()):
    a,b=map(int,raw_input().split(","))
    tmp=number[a-1]
    number[a-1]=number[b-1]
    number[b-1]=tmp
print '\n'.join(map(str,number))

Solution (Python):


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

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

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

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

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

Solution (Python):
l=range(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

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

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

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

Solution (Python):



import sys
import math

w = int(input())
n = int(input())
s = []

for _ in range(n):
    x = input().split(',')
    s.append((int(x[0]), int(x[1])))

result = [i for i in range(1, w+1)]

for x, y in s:
    result[x-1], result[y-1] = result[y-1], result[x-1]

for x in result:
    print(x)

Solution (Python):


n = input()
m = input()
line = []
for i in range(0, n):
    line.append(i)
for i in range(0, m):
    change = map(int, raw_input().split(','))
    change[0] -= 1
    change[1] -= 1
    line[change[0]], line[change[1]] = line[change[1]], line[change[0]]
for i in range(0, n):
    print line[i] + 1

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

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

nums = list(range(1, w + 1))
for i in range(n):
    ab = input().split(",")
    a = int(ab[0]) - 1
    b = int(ab[1]) - 1

    _a = nums[a]
    nums[a] = nums[b]
    nums[b] = _a
print("\n".join([str(n) for n in nums]))

Solution (Python):





w = int(raw_input())
n = int(raw_input())
change = [0 for _ in xrange(n)]
for i in xrange(n):
    change[i] = eval(raw_input())
List = range(1,w+1)
for i,j in change:
    List[i-1],List[j-1] = List[j-1],List[i-1]
for i in List:
    print i

Solution (Python):
w=int(raw_input())
 
number = range(1,w+1)
for i in xrange(input()):
    a,b=map(int,raw_input().split(","))
    tmp=number[a-1]
    number[a-1]=number[b-1]
    number[b-1]=tmp
print '\n'.join(map(str,number))

Solution (Python):
w=int(raw_input())
l=range(w+1)
n=int(raw_input())
for i in range(n):
    x,y=map(int,raw_input().split(','))
    l[x],l[y]=l[y],l[x]
for i in range(1,w+1):
    print l[i]

Solution (Python):
def main():
    LIST=[]
    for i in range(int(input())):
        LIST.append(i+1)

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

    for i in LIST:
        print(str(i))
            
    
if __name__ == '__main__':
    main()

Solution (Python):
w = int(input())
n = int(input())
lines = []
for i in range(n):
    a, b = map(int, input().split(","))
    lines.append([a, b])
lines = list(reversed(lines))
for j in range(1, w + 1):
    for line in lines:
        if line[0] == j:
            j = line[1]
        elif line[1] == j:
            j = line[0]
    print(j)

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

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

Solution (Python):
while True:
	try:
		n = int(raw_input())
		ans = [i for i in range(n+1)]
		m = int(raw_input())
		for i in range(m):
			a, b = map(int, raw_input().strip().split(','))
			t = ans[a]
			ans[a] = ans[b]
			ans[b] = t
		ans = ans[1:]
		for x in ans:
			print x
	except EOFError:
		break

Solution (Python):
w=int(input())
n=int(input())
a=[]
for i in range(w):
    a.append(i+1)
for i in range(n):
    m, n= map(int,input().split(','))
    temp=a[m-1]
    a[m-1]=a[n-1]
    a[n-1]=temp
for i in range(w):
    print(a[i])

Solution (Python):
import sys

lines = sys.stdin.readlines()
w = lines[0]
n = lines[1]
exchanges = lines[2:len(lines)]

ret = list(range(1,int(w)+1))

for line in exchanges:
    line = line.split(",")
    inp = []
    for i in line:
        inp.append(int(i))
    ret[inp[0]-1],ret[inp[1]-1] = ret[inp[1]-1],ret[inp[0]-1]

for i in ret:
    print (i)

Solution (Python):
w, n = int(input()), int(input())

l = list(range(w + 1))

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

print('\n'.join([str(i) for i in l[1:]]))

Solution (Python):

def replace(num1,num2,nums):
    tmp = nums[num1-1]
    nums[num1-1]=nums[num2-1]
    nums[num2-1]=tmp

w = input()
nums = [x+1 for x in xrange(w)]
n = input()
for x in xrange(n):
    num1,num2 = map(int,raw_input().split(","))
    replace(num1,num2,nums)
for num in nums:
    print num

Solution (Python):
while True:
    try:
        n = int(raw_input())
        ans = [i for i in range(n+1)]
        m = int(raw_input())
        for i in range(m):
            a, b = map(int, raw_input().strip().split(','))
            t = ans[a]
            ans[a] = ans[b]
            ans[b] = t
        ans = ans[1:]
        for x in ans:
            print x
    except EOFError:
        break

Solution (Python):
w = int(input())
n = int(input())
l = [list(map(int, input().split(','))) for x in range(n)]

res = [0] * (w + 1)
for i in range(1, w + 1):
    c = i
    for a in l:
        if a[0] == c:
            c = a[1]
        elif a[1] == c:
            c = a[0]

    res[c] = i

for r in res[1:]:
    print(r)

Solution (Python):
w = int(input())
n = int(input())
l = list(reversed([list(map(int, input().split(','))) for x in range(n)]))

for i in range(1, w + 1):
    c = i
    for a in l:
        if a[0] == c:
            c = a[1]
        elif a[1] == c:
            c = a[0]

    print(c)

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

Solution (Python):
W = int(input())
ary = list(range(1, W + 1))
N = int(input())
for i in range(N):
    x,y = map(int,input().split(','))
    ary[x - 1], ary[y - 1] = ary[y - 1], ary[x - 1]
for i in ary:
    print(i)

Solution (Python):


me,ans = [],[]
x = input()
y = input()
for i in xrange(y):
    me.append(map(int,raw_input().split(",")))

for i in xrange(x):
    i += 1
    for j in xrange(y):
        if i == me[j][0]:
            i = me[j][1]
        elif i == me[j][1]:
            i = me[j][0]

    ans.append(i)
for i in xrange(x):
    for j in xrange(x):
        if i + 1 == ans[j]:
            print j + 1

Solution (Python):

def main():
    w = int(input())
    n = int(input())
    nums = list(range(1, w + 1))
    for _ 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)
if __name__ == '__main__':
    main()

Solution (Python):



import sys

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

lst = range(1, w+1)

for num in sys.stdin:
    nums = num.split(",")
    a1 = int(nums[0]) - 1
    b1 = int(nums[1]) - 1

    a2 = lst[a1]
    b2 = lst[b1]
    lst[a1] = b2
    lst[b1] = a2

for i in lst:
    print(i)

Solution (Python):


w = int(raw_input())
num = []
for i in range(w+1):
    num.append(i)
n = int(raw_input())
for i in range(n):
    a, b = map(int, raw_input().split(','))
    num[a], num[b] = num[b], num[a]
for i in range(1, w+1):
    print num[i]

Solution (Python):
w = int(input())
Ver = list(range(1, w+1))

n = int(input())

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

    temp = Ver[j-1]
    Ver[j-1] = Ver[k-1]
    Ver[k-1] = temp

for i in range(len(Ver)):
    print(Ver[i])

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

for x in li:
    print(x)

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

Solution (Python):



def change(List,a,b):
    temp = List[a-1]
    List[a-1] = List[b-1]
    List[b-1] = temp

w = input()
n = input()

Lot = [i for i in xrange(1,w+1)]

for j in xrange(n):
    l = map(int, raw_input().split(","))
    change(Lot,l[0],l[1])

for k in xrange(len(Lot)):
    print Lot[k]

Solution (Python):
import sys
w = int(input())
n = int(input())

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

a = [None] * (n)
b = [None] * (n)
for i,line in enumerate(sys.stdin.readlines()):
   a[i], b[i] = map(int, line.split(","))

def swap(x, y):
    global state 
    temp = state[x-1]
    state[x-1] = state[y-1]
    state[y-1] = temp


for i in range(n):
    swap(a[i], b[i])

for x in state:
    print(x)

Solution (Python):
w = int(input())
arr = [i+1 for i in range(w)]
for i in range(int(input())):
    s = input().split(",")
    a,b = int(s[0]), int(s[1])
    temp = arr[a-1]
    arr[a-1] = arr[b-1]
    arr[b-1] = temp
for i in range(w):
    print(arr[i])

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

Solution (Python):



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(','))
        a -= 1
        b -= 1
        l[a], l[b] = l[b], l[a]

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

solve()

Solution (Python):

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

Solution (Python):
w = int(raw_input())
n = int(raw_input())

ans = [i for i in range(1, w+1)]

for i in range(n):
  a, b = map(int, raw_input().split(','))

  ans[a-1], ans[b-1] = ans[b-1], ans[a-1]

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

Solution (Python):
w = int(raw_input())
n = int(raw_input())

ans = [i for i in range(1, w+1)]

for i in range(n):
  a, b = map(int, raw_input().split(','))

  ans[a-1], ans[b-1] = ans[b-1], ans[a-1]

for i in ans:
  print i

Solution (Python):
w = int(input())
n = int(input())
ans = [0 for i in range(w)]
list = []

for i in range(n):
    ll = input().split(",")
    a, b = ll[0], ll[1]
    a = int(a)
    b = int(b)
    list.append([a,b])


for i in range(1,w+1):
    position = i-1

    for ll in list:
        a, b = ll[0], ll[1]
        if position == a-1:
            position = b-1
        elif position == b-1:
            position = a-1
        else:
            pass
    ans[position] = i
for j in ans:
    print(j)

Solution (Python):
w = eval(input())
n = eval(input())
numlist = [item for item in range(1, w + 1)]
for t in range(n):
	i, j = [eval(item) - 1 for item in input().split(',')]
	numlist[i], numlist[j] = numlist[j], numlist[i]
for item in numlist:
	print(item)

Solution (Python):
w=list(range(int(input())+1))
for _ in[0]*int(input()):
 a,b=map(int,input().split(','))
 w[a],w[b]=w[b],w[a]
for i in range(1,len(w)):print(w[i])

Solution (Python):
w = int(input())
n = int(input())
vertical = [x for x in range(1, w + 1)]

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

for i in vertical:
    print(i)

Solution (Python):
w = input()
n = input()
line = [[0 for i in xrange(n)] for j in xrange(w + 1)]
for i in xrange(n):
    a, b = map(int, raw_input().split(','))
    line[a][i] = b
    line[b][i] = a
for i in xrange(1, w + 1):
    num = i
    for j in xrange(n - 1, -1, -1):
        if line[num][j] > 0: num = line[num][j]
    print num

Solution (Python):
def swap(a, b, row):
    row[a-1], row[b-1] = row[b-1], row[a-1]  

w = int(raw_input())
n = int(raw_input())

result = range(1, w+1)

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

for x in result:
    print x

Solution (Python):
line=input()
order=[]
for i in range(line):
	order.append(i+1)

time=input()
for n in range(time):
	inp=raw_input()
	num_pre=list(inp)
	num=[]
	if num_pre.index(",")==2:
		num.append(int(num_pre[0]+num_pre[1]))
	else:
		num.append(int(num_pre[0]))
	if len(num_pre)-num_pre.index(",")==3:
		num.append(int(num_pre[-2]+num_pre[-1]))
	else:
		num.append(int(num_pre[-1]))
	a=order[num[0]-1]
	b=order[num[1]-1]
	order[num[0]-1]=b
	order[num[1]-1]=a

for m in range(line):
	print order[m]

Solution (Python):

w=int(input())
L=[i for i in range(1,w+1)]
n=int(input())
for i in range(n):
    a,b=[int(j)-1 for j in input().split(",")]
    s=L[a]
    L[a]=L[b]
    L[b]=s
[print(i) for i in L]

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

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

Solution (Python):
w = int(input().replace("\n", ""))
n = []
for i in range(int(input().replace("\n", ""))):
    n.append([int(v) for v in input().replace("\n", "").split(",")])

m = [0] * (w + 1)
for i in range(1, w + 1):
    step = i
    for j in range(0, len(n)):
        if n[j][0] == step:
            step = n[j][1]
        elif n[j][1] == step:
            step = n[j][0]
    m[step] = i
del m[:1]
print("\n".join(map(str, m)))

Solution (Python):


import sys

def amida(w, side_bar):
    result = []
    side_bar.reverse()
    for x in range(1, w+1):
        status = x
        for bar in side_bar:
            if status == bar[0]:
                status = bar[1]
            elif status == bar[1]:
                status = bar[0]
        result.append(status)
    return result

def main():
    W = int(input())
    N = int(input())
    side_bar = [tuple(map(int, input().split(','))) for line in range(N)]
    result = amida(W, side_bar)
    for r in result:
        print(r)

if __name__ == '__main__':
    main()

Solution (Python):
li = [i for i in range(int(input())+1)]
for i in range(int(input())):
    line = list(map(int, input().split(',')))
    li[line[0]],li[line[1]] = li[line[1]],li[line[0]]
for i in li[1::]: print(i)

Solution (Python):
w = input()
n = input()
A = range(1, w+1)
for _ in xrange(n):
    a, b = map(int, raw_input().split(','))
    A[a-1], A[b-1] = A[b-1], A[a-1]
for a in A:
    print a

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

nums = [i for i in range(1,w+1)]

for i in range(n):
    try:
        a, b = list(map(lambda x:int(x)-1, input().split(",")))
    except EOFError:
        break
    nums[a], nums[b] = nums[b], nums[a]

for i in nums:
    print(i)

Solution (Python):
w = int(input())
n = int(input())
Ami = []
Num = []
for i in range(n):
    Ami.append(list(map(int,input().split(","))))
for i in range(1,w+1):
    pos = i
    for j in range(n):
        if pos == Ami[j][0]:
            pos = Ami[j][1]
        elif pos == Ami[j][1]:
            pos = Ami[j][0]
    Num.append([pos,i])
Num = sorted(Num)
for k in range(0,w):
    print(Num[k][1])

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

Solution (Python):
def get_another_num(data, me):
    if data[0] == me:
        return data[1]
    else:
        return data[0]


if __name__ == '__main__':
    
    
    
    
    v_lines = int(input())
    h_lines = int(input())
    data = []
    for i in range(h_lines):
        data.append(tuple(map(int, input().split(','))))


    
    results = [0] * (v_lines + 1)
    for i in range(1, v_lines + 1):
        me = i
        for amida in data:
            if me in amida:
                me = get_another_num(amida, me)
        results[me] = i

    
    for i in range(1, v_lines + 1):
        print(results[i])

Solution (Python):
w = int(input())
amida = list(range(1,w+1))
n = int(input())
for i in range(0,n):
  exchange = list(map(int,input().split(",")))
  amida[exchange[1]-1], amida[exchange[0]-1] = amida[exchange[0]-1], amida[exchange[1]-1]
for i in amida:
  print(i)

Solution (Python):
w = [v+1 for v 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]
print('\n'.join(map(str, w)))

Solution (Python):
w=eval(input())
n=eval(input())
edge=[]
for i in range(n):
    edge.append(tuple(map(int,input().split(','))))
for i in range(1,w+1):
    temp=i
    for j in range(n):
        if temp in edge[n-j-1]:
            temp=edge[n-j-1][edge[n-j-1].index(temp)-1]
    print(temp)

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

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

Solution (Python):

 
import sys
 
def amida(w, side_bar):
    result = []
    side_bar.reverse()
    for x in range(1, w+1):
        status = x
        for bar in side_bar:
            if status == bar[0]:
                status = bar[1]
            elif status == bar[1]:
                status = bar[0]
        result.append(status)
    return result
 
def main():
    W = int(input())
    N = int(input())
    side_bar = [tuple(map(int, input().split(','))) for line in range(N)]
    result = amida(W, side_bar)
    for r in result:
        print(r)
 
if __name__ == '__main__':
    main()

Solution (Python):
w = int(raw_input().rstrip())

l=[]
for i in range(w+1):
  l.append(i) 

n = int(raw_input().rstrip())

for i in range(n):
  a, b = raw_input().rstrip().split(",")
  l[int(a)], l[int(b)] = l[int(b)], l[int(a)]


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

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

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

for i in ans:
    print(i+1)

Solution (Python):
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 range(w):
    print(l[i])

Solution (Python):


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

Solution (Python):


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

Solution (Python):
import sys
import math as mas

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

Solution (Python):


import sys
import os
import math


tate = int(input())
yoko = int(input())
values = [i for i in range(tate)]


for _ in range(yoko):
    a, b = map(int, input().split(','))
    a -= 1
    b -= 1
    values[a], values[b] = values[b], values[a]

for i in values:
    print(i+1)

Solution (Python):
list = {}
for a in range(1, int(input()) + 1) : list[a] = a
for a in range(int(input())) :
    x, y = [int(temp) for temp in input().split(',')]
    temp = list[x]
    list[x] = list[y]
    list[y] = temp
for a in range(1, len(list) + 1) : print(list[a])

Solution (Python):
w = int(input())
n = int(input())
a = list(range(w))
for i in range(n):
    k1,k2 = map(int,input().split(","))
    a[k1-1],a[k2-1] = a[k2-1],a[k1-1]
for i in a:
    print(i+1)

Solution (Python):
import sys


num = input()
list = {}
for i in range(1, int(num) + 1): 
    list[i] = i
    
for i in range(int(input())) :
    x, y = map(int, input().split(','))
    
    temp = list[x]
    list[x] = list[y]
    list[y] = temp
    
for i in range(1, len(list) + 1):
    print(list[i])

Solution (Python):
import sys

lines = str(sys.stdin.read()).strip().split("\n")
W = int(lines.pop(0))
N = int(lines.pop(0))

results = list(range(1,W + 1))

for i in range(N):
    data = list(map(lambda i: int(i) - 1, lines[i].split(",")))
    results[data[0]], results[data[1]] = results[data[1]], results[data[0]]

for result in results:
	print(result)

Solution (Python):
def main():
    w = int(input())
    n = int(input())
    ans =[i for i in range(1, w+1)]

    def change(li, a, b):
        tmp = li[a-1]
        li[a-1] = li[b-1]
        li[b-1] = tmp
        return li

    for _ in range(n):
        a, b = map(int, input().split(","))
        ans = change(ans, a, b)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Solution (Python):
import sys
n = int(sys.stdin.readline().rstrip())
m = int(sys.stdin.readline().rstrip())
l = []
for i in range(m):
    l.append(list(map(int, sys.stdin.readline().rstrip().split(','))))
for i in range(n):
    cur = i+1
    for d in l[::-1]:
        if cur in d:
            cur = d[0] if cur == d[1] else d[1]
    print(cur)

Solution (Python):
w, n = int(input()), int(input())
p = list(range(1, w + 1))
l = [list(map(int, input().split(","))) for i in range(n)]
for j in l: p[j[0] - 1], p[j[1] - 1] = p[j[1] - 1], p[j[0] - 1]
k = [print(v) for v in p]

Solution (Python):





def main():
    w = int(input())
    n = int(input())

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

        xs[a], xs[b] = xs[b], xs[a]

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

if __name__ == "__main__": main()

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

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

Solution (Python):
w = int(input())
n = int(input())
a = [[int(i) for i in input().split(",")] for j in range(n)]
b = [0 for i in range(w)]
for i in range(1, w+1):
    next_num = i
    for j in a:
        if next_num == j[0]:
            next_num = j[1]
        elif next_num == j[1]:
            next_num = j[0]
    b[next_num - 1] = i
for i in range(w):
    print(b[i])

Solution (Python):
user = input()
w = int(user)
user = input()
n = int(user)
a = []
b = []
now = 0
for i in range(n):
    user = input()
    users = user.split(",")
    a.append(int(users[0]))
    b.append(int(users[1]))

for j in range(1, w+1):
    now = j
    for k in reversed(range(n)):
        if now == a[k]:
            now = b[k]
        elif now == b[k]:
            now = a[k]
    print(now)

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


         
w = int(input())
slots = list(range(1, w + 1))
n = int(input())
for k in range(n):
    a, b = [int(_) for _ in input().split(',')]
    slots[a-1], slots[b-1] = slots[b-1], slots[a-1]
for s in slots:
    print(s)

Solution (Python):
w=int(input())
n=int(input())
a=[]
b=[]
Ans=[int(0) for i in range(w)]
for i in range(n):
    x,y=[int(j) for j in input().split(",")]
    a.append(x)
    b.append(y)
for i in range(1,w+1):
    ans=i
    for j in range(len(a)):
        if ans==a[j]:
            ans=b[j]
        elif ans==b[j]:
            ans=a[j]
    Ans[ans-1]=i
for i in range(w):
    print(Ans[i])

Solution (Python):
W = int(input())
N = int(input())
edges = [tuple(map(lambda c:int(c)-1, input().split(","))) for _ in [0]*N]
result = list(range(1, W+1))

for a, b in edges:
    result[a], result[b] = result[b], result[a]

print("\n".join(map(str, result)))

Solution (Python):
import sys
w = int(input())
n = int(input())
l = list()
for _ in range(n):
    l.append(list(map(int,input().split(","))))

res = [0 for _ in range(w)]
for i in range(1,w+1):
    tgt = i
    for num in l:
        if tgt in num:
            if num.index(tgt) == 1:
                tgt = num[0]
            else:
                tgt = num[1]
    res[tgt-1] = i

for x in res:
    print(x)

Solution (Python):
stick = [i for i in range(1, int(input()) + 1)]

net = int(input())

for _ in range(net):
    a, b = list(map(int, input().split(",")))
    stick[a - 1], stick[b - 1] = stick[b - 1], stick[a - 1]
for v in stick:
    print(v)

Solution (Python):

if __name__ == '__main__':
    w = (int)(input())
    n = (int)(input())
    a = [i+1 for i in range(0,w)]
    for i in range(n):
        x,y = map(int,input().split(","))
        a[x-1],a[y-1] = a[y-1],a[x-1]
    for x in a:
        print(x)

Solution (Python):
w = int(input().rstrip())
n = int(input().rstrip())

amida = [i for i in range(w)]

for i in range(n):
    a = input().rstrip().split(",")
    number = [int(i) - 1 for i in a]
    amida[number[0]], amida[number[1]] = amida[number[1]], amida[number[0]]

for i in amida:
    print(i + 1)

Solution (Python):



def list_swap(given_list: list, swap_number1: int, swap_number2: int)-> list:
    return_list = given_list[:]
    memo = given_list[swap_number1 - 1]
    return_list[swap_number2 - 1] = memo
    memo = given_list[swap_number2 - 1]
    return_list[swap_number1 - 1] = memo
    return return_list


if __name__ == '__main__':
    w = int(input())
    amida_number = [i for i in range(1, w+1)]
    n = int(input())
    for j in range(n):
        a, b = map(int, input().split(','))
        amida_number = list_swap(amida_number[:], a, b)
    [print(amida_number[k]) for k in range(w)]

Solution (Python):


w = int(raw_input())
n = int(raw_input())

yoko = []
for i in range(n):
	data = map(int, raw_input().split(","))
	yoko.append(data)

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

for num in range(1,w+1):

	direction = num
	for c in yoko:
		if c[0] == direction:


			direction = c[1]
		elif c[1] == direction:


			direction = c[0]
	ans[direction-1] = num

for i in ans:
	print(i)

Solution (Python):
w = int(input())
n = int(input())
goal = [i for i in range(1,w+1)]
for i in range(n):
    a,b = [int(j) for j in input().split(',')]
    goal[a-1],goal[b-1] = goal[b-1],goal[a-1]
for po in goal:
    print(po)

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

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

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

Solution (Python):
def main():
    n = int(input())
    point = int(input())
    A = []
    for i in range(n):
        A.append(i+1)
    for i in range(point):
        a,b = map(int,input().split(","))
        A[a-1],A[b-1] = A[b-1],A[a-1]
    for value in A:
        print(value)
      


if __name__ == '__main__':
    main()

Solution (Python):
data = []
w = int(input())
for i in range(w):
  data.append(i+1)

n = int(input())

for line in range(n):
  a, b = [int(i) for i in input().split(',')]
  data[a-1], data[b-1] = data[b-1], data[a-1]
for d in data:
  print(d)

Solution (Python):
a = list(map(lambda x: x+1, range(int(input()))))
for _ in range(int(input())):
    m,n = map(lambda x: int(x)-1, input().split(','))
    a[m], a[n] = a[n],a[m]
for i in a:
    print(i)