n = int(input())
a_lst = list(map(int, input().split()))
q = int(input())
# b_lst = []
# c_lst = []
cnt = []
ans = []
# ans = a_lst.copy()
for i in range(q):
    x, y = map(int, input().split())

    # b_lst.append(x)
    # c_lst.append(y)
    a_lst = [y if j == x else j for j in a_lst]
    ans.append(a_lst)

for i in range(len(ans)):
    print(sum(ans[i]))
# for i in range(q):

#     for j in range(len(a_lst)):
#         if a_lst[j] == b_lst[i]:
#             a_lst[j] = c_lst[i]
#     cnt.append(sum(a_lst))
#     print(cnt[i])

# print(cnt)
# for i in range()
# print(b_lst)