n = int(input())
l_a = list(map(int, input().split()))
ans = []
q = int(input())
for _ in range(q) :
    b, c = map(int, input().split())
    for i in range(n) :
        if l_a[i] == b :
            l_a[i] = c
    ans.append(sum(l_a))

for value in ans :
    print(value)
