N = int(input())
A = list(map(int,input().split()))

num_count = [0]*(10**5+1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1

for q in range(int(input()):
    B,C = map(int,input().split())
    gain = C*(num_count[B])
    loss = B*(num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + gain - loss
    print(tmp_sum)
