n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
num=[0]*(10**5)
sum=sum(a)
for i in range(q):
    x=bc[i][0]
    y=bc[i][1]
    c=a.count(x)
    ind=[j for j,m in enumerate(a) if m == x]
    sum+=(y-x)*(c+num[x-1])
    num[y-1]+=c
    num[x-1]-=c
    print(num)
    print(sum)