n = int(input())
a = list(map(int,input().split()))
q = int(input())

g = []
t = sum(a)
s = []

for j in range(100001):
    h = a.count(j)
    g.append(h)

for i in range(q):
    b,c = map(int,input().split())
    if g[b] != 0:
        t = t + c*g[b] - b*g[b]
        g[c] = g[c] + g[b]
        g[b] = 0
        s.append(t)
    else:
        s.append(t)

for m in range(q):
    print(s[m])
