import collections

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bcs=[list(map(int,input().split())) for i in range(Q)]
total=sum(A)
c=collections.Counter(A)
ans=[0 for i in range(Q)]




for i in range(Q):
    B=bcs[i][0]
    C=bcs[i][1]
    if c[B]!=0:
        tempcounterpl=collections.Counter([C for j in range(c[B])])
        total=total+c[B]*(C-B)
        ans[i]=total
        c[B]=0
        c=c+tempcounterpl
    else:
        ans[i]=total
for i in range(Q):
    print(ans[i])