import numpy as np
n = int(input())
A = list(map(int,input().split()))
q = int(input())
B = []
C = []
for _ in range(q):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)
B = np.array(B)
C = np.array(C)
for i in range(q):
    A = [C[i] if a == B[i] else a for a in A]
    print(sum(A))