N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for q in range(Q):
    newB, newC = map(int,input().split())
    B.append(newB)
    C.append(newC)

all_sum = sum(A)
rep = []
for i in range(Q):
    count = A.count(B[i])
    count_rep = rep.count(B[i])
    diff = (C[i] - B[i]) * (count + count_rep)
    all_sum += diff
    for t in range(count):
        rep.append(C[i])
    print(all_sum)