n, *bc = map(int, open(0).read().split())
a = [bc.pop(0) for _ in range(n)]
q = bc.pop(0)

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)