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")

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")



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")

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")

-am = [i for i in range(w + 1)] +kuji = [i + 1 for i in range(w)] -    am[a], am[b] = am[b], am[a] -print(*am[1:], sep="\n") +    kuji[a - 1], kuji[b - 1] = kuji[b - 1], kuji[a - 1] +print(*kuji, sep="\n")