w = int(eval(input()))

n = int(eval(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)
w = int(eval(input()))

n = int(eval(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)
w = int(eval(input()))
n = int(eval(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)

w = int(eval(input()))
n = int(eval(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)

-l = [list(map(int, input().split(","))) for x in range(n)] -res = [0] * (w + 1) +l = list(reversed([list(map(int, input().split(","))) for x in range(n)])) -    res[c] = i -for r in res[1:]: -    print(r) +    print(c)