import numpy as np
N=int(input())
z=input()
a=z.split()
A=[]
B=[]
C=[]
flag=[]
replace=0
for n in range(100001):
    flag.append(1)
for i in range(N):
    A.append(int(a[i]))
Q=int(input())
for j in range(Q):
    d=input()
    D=d.split()
    B.append(int(D[0]))
    C.append(int(D[1]))
A.sort()
for j in range(Q):
    if flag[B[j]]==1:
        k=0
        replace=0
        while A[k]<=B[j]:
            if A[k]==B[j]:
               A[k]=C[j]
               replace+=1
            k+=1
            if k==N:
                break
        if replace>0:
            flag[B[j]]=0
            flag[C[j]]=1
    A.sort()
    print(sum(A))

