import numpy as np
N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
for i in range(Q):
    B,C = [int(x) for x in input().split()]
    A = [C if a == B else a for a in A]
    print(np.sum((np.array(A))))