number = int(input())

numbers = [i for i in range(1, number+1)]
print(' '.join(map(str, numbers)))
count = int(input())

sum_numbers = []
for i in range(count):
    before, after = map(int, input().split())
    numbers = [after if value == before else value for value in numbers]
    sum_numbers.append(sum(numbers))

for i in range(count):
    print(sum_numbers[i])
