# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
xy = [map(int, input().split()) for _ in range(Q)]
x, y = [list(i) for i in zip(*xy)]


def replace_list(num_list):
    num_list = [y[index] if j==i else j for j in num_list]
    return num_list

for index, i in enumerate(x):
    A = replace_list(A)
    print(sum(A))
