n = int(input())
lst = list(map(int, input().split()))
q = int(input())
res = []
for _ in range(q):
    x = list(map(int, input().split()))
    for i in range(n):
        if lst[i] == x[0]:
            lst[i] = x[1]
    res.append(sum(lst))

for i in res:
    print(i)

      