import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    if B not in A:
        print(np.sum(A))
    else:
        A = np.where(A==B, C, A)              
        print(np.sum(A))