n0 = int(1e5)+1
x = [0]*n0

n = int(input())
a0 = list(map(int,input().split()))
q = int(input())
bcs = []
for i in range(q):
    bcs.append(list(map(int,input().split())))

for a in a0:
    x[a] += 1

for bc in bcs:
    x[bc[1]] += x[bc[0]]
    x[bc[0]] = 0
    sum0 = 0
    for i in range(n0):
        sum0 += i*x[i]
    print(sum0)