sum=0
dic={}
n=int(input())
lis=input()
lis=lis.split(' ')
def con(a,b):
    if b in dic:
        dic[b]=dic[b]+dic[a]
    else:
        dic[b]=dic[a]
for i in lis:
    sum=sum+int(i)
    if int(i) in dic:
        dic[int(i)]=dic[int(i)]+1
    else:
        dic[int(i)]=1
#print(dic)
#print(sum)
q=int(input())
for i in range(0,q):
    que=input()
    que=que.split()
    que[0]=int(que[0])
    que[1]=int(que[1])
    if que[0] in dic:
        if que[0]>que[1]:
            sum=sum-(que[0]-que[1])*dic[que[0]]
            con(que[0],que[1])
        else:
            sum=sum+(que[1]-que[0])*dic[que[0]]
            con(que[0],que[1])
    print(sum)
        
