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)

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)
