import sys
N = int(input())
A = list(map(int, input().split()))
Q = int(input())


for q in range(Q):
    b, c = map(int, input().split())
    ind = [i for i, x in enumerate(A) if x==b]
    for i in ind :
        A[i] = c
    print(sum(A))