n    = int(input())
a_s  = list(map(int, input().split()))
q    = int(input())
bc_s = [ list(map(int, input().split())) for _ in range(q) ]

s = sum(a_s)
m = { n: 0 for n in a_s }

for a in a_s:
    m[a] += 1

for b, c in bc_s:
    nb = m.get(b, 0)
    s += nb * (c - b)
    print(s)
    m[c] = nb + m.get(c, 0)
