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

for b, c in bc:
    sumA = 0
    for i in range(0, n):
        if a[i] == b:
            a[i] = c
        sumA += a[i]
    print(sumA)
            