n=int(input(''))
a=input('')
a=a.split(' ')
for b in range(n):
    a[b]=int(a[b])

q=int(input(''))
b=[]
c=[]

for i in range(q):
    x,y=map(int,input('').split(' '))
    b.append(x)
    c.append(y)

v=[]
for i in range(10**5+1):
    v.append(0)

for i in range(n):
    v[a[i]]+=1

for i in range(q):
    s=0
    v[c[i]]+=v[b[i]]
    v[b[i]]=0
    for j in range(10**5+1):
        if v[j]>0:
            s=s+j*v[j]

    print(s)