n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int, input().split())) for i in range(q)]

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