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

for i in range(Q):
    for j in range(N):
        if A[j] == B[i]:
            A[j] = C[i]
    print(sum(A))

