n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
b = []
for _ in range(q):
    b.append([int(i) for i in input().split()])


for i in range(q):
    for j in range(n):
        if a[j] == b[i][0]:
            a[j] = b[i][1]
    print(sum(a))

