#-*- using:utf-8 -*-

import collections

N = int(input())
A = list(map(int, input().split()))
ACC = collections.Counter(A)
Q = int(input())
ASum = []

for _ in range(Q):
    B,C = map(int, input().split())
    ACC[C] += ACC[C]
    ACC[B] = 0
    goukei = 0
    for i in ACC.keys():
        goukei += int(i) * int(ACC[i])
    ASum.append(goukei)
    
for i in range(len(ASum)):
    print(ASum[i])