N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

for i in range(Q):
    if(B[i] in A):
        count = A.count(B[i])

        d = C[i] - B[i]
        total += count * d
        print(total)

        A = [C[i] if x == B[i] else x for x in A]
