n = int(input())

a = list(map(int,input().split()))
#print(a)
q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1

b = []
for _ in range(q):
    b.append(list(map(int,input().split())))
#print(b)


for i in range(q):
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    #print(z[:5])
    s = 0
    for j in range(len(z)):
        s += j * z[j]
    print(s)