import collections

def add(c):
    return sum([int(k)*int(v) for k, v in c.items()])

n = int(input())
a = [int(each) for each in input().split()]
q = int(input())
rep = [tuple(int(each) for each in input().split()) for i in range(q)]

s = [str(sum(a))]

c = collections.Counter(a)
for i in range(q):
    # 存在しないときにエラーになる
    if c.get(rep[i][0]):
        c[rep[i][1]] += c.pop(rep[i][0])
    s.append(add(c))
print('\n'.join([str(each) for each in s[1:]]))