n = int(input())
a = list(map(int,input().split()))
q = int(input())

import collections
a = collections.Counter(a)
for i in range(q):
    b,c = list(map(int,input().split()))
    d = a[b]
    a[b] = 0
    a[c] += d
    print(sum([key*value for key,value in a.items()]))