import collections
N = input()
inp = map(int, input().split())
dic = dict(collections.Counter(inp))
wa = 0
for i in range(len(dic)):
    wa += list(dic.keys())[i] * list(dic.values())[i]
for i in range(int(input())):
    a, b = map(int, input().split())
    se = set(dic.keys())
    if a in se:
        wa += dic[a] * (b-a)
        if b in se:
            pass
        else:
            dic[b] = 0
        dic[b] += dic[a]
        dic[a] = 0
    print(wa)