

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
bc = []
d = {}
suma = sum(a)
for nr in a:
    if nr not in d:
        d[nr] = 1
    else:
        d[nr] += 1

for i in range(q):
    bc = [int(i) for i in input().split()]
    b = bc[0]
    c = bc[1]
    if b not in d:
        print(suma)
        continue
    suma = suma + (c - b) * d[b]
    if c not in d:
        d[c] = d[b]
    else:
        d[c] += d[b]
    print(suma)


