import sys
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [list(map(int, sys.stdin.readline().split())) for i in range(Q)]
for i in range(Q):
    B, C = BC[i]
    A[A == B] = C
    print(sum(A))