n = int(input())
a = (list(map(int, input().split())))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
sum = 0
for i in range(q):
    for j in range(n):
        if a[j] == bc[i][0]:
            a[j] = bc[i][1]
    for k in range(n):
        sum += a[k]
    print(sum)
    sum = 0
