from collections import Counter, defaultdict

def update(dic, b, c):
    dic = dic.copy()
    n = dic.pop(b)
    dic[c] += n
    return dic

def calc_diff(dic, b, c):
    return c * dic[b] - b * dic[b]

def calc_total(dic):
    return sum(k * v for k, v in dic.items())

N = int(input())
lis = list(map(int, input().split()))
dic = defaultdict(int)
dic.update(Counter(lis))
Q = int(input())
total = calc_total(dic)
for _ in range(Q):
    B, C = map(int, input().split())
    total += calc_diff(dic, B, C)
    print(total)
    dic = update(dic, B, C)