N = int(input())


A = list(map(int,input().split()))
ok = [0]*pow(10,5)
Q = int(input())

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

f):
    ok[A[i]]+=1
memo1=0
memo2=0

S = sum(A)
for i in range(Q):

    S+=ok[li[i][0]]*(li[i][1]-li[i][0])
    print(S)
    a = ok[li[i][0]]
    ok[li[i][1]]+=a
    ok[li[i][0]]=0
    
    if max(ok)==N:
        memo1=i
        memo2=ok.index(N)
        break



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)