w = int(eval(input()))

n = int(eval(input()))

lines = []

for i in range(n):

    a, b = list(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)
w = int(eval(input())) + 1

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

n = int(eval(input()))

for i in range(n):

    a, b = list(map(int, input().split(",")))

    l[a], l[b] = l[b], l[a]

for i in range(1, w):

    print((l[i]))
w = int(eval(input()))
n = int(eval(input()))
lines = []
for i in range(n):
    a, b = list(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)

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

-w = int(eval(input())) +w = int(eval(input())) + 1 +l = [i for i in range(w)] -lines = [] -    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) +    l[a], l[b] = l[b], l[a] +for i in range(1, w): +    print((l[i]))