N= int(input())
from collections import Counter

A = list(map(int,input().split()))

Q = int(input())

li = [list(map(int,input().split())) for i in range(Q)]


memo2=0

S = sum(A)
cou = Counter(A)

for i in range(Q):
    global ohno
    S+=cou[li[i][0]]*(li[i][1]-li[i][0])
    print(S)
    a = cou[li[i][0]]
    cou[li[i][1]]+=a
    cou[li[i][0]]=0
    
    if set(cou.values())==1:
        global ohno
        memo1=i
        memo2=cou[max(cou.values())]
        for i in range(memo1+1,Q):
            if li[i][0]==memo2:
                print(N*li[i][1])
                memo2=li[i][1]
            else:
                print(memo2*N)