N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i],C[i] = map(int,input().split())

for i in range(Q):
    if B[i] in A:
        list = [j for j, x in enumerate(A) if x == B[i]]
        for j in range(len(list)):
            A[list[j]] = C[i]
    print(sum(A))