N=int(input())
alist=list(map(int, input().split()))
Q=int(input())
bclist=[]
bcdic={}
for i in range(Q):
    bclist.append(list(map(int, input().split())))
def repsum(alist,bc):
    alist.sort()
    for i in range(N):
        if alist[i]==bc[0]:
            alist[i]=bc[1]
        elif alist[i]>bc[0]:
            break
    return alist
n=0
for bc in bclist:
    if n==0:
        alist=repsum(alist,bc)
        s=sum(alist)
        print(s)
        n=1
    else:
        alist=repsum(alist,bc)
        nb=alist.count(bc[0])
        s=s+(bc[1]-bc[0])*nb
        print(s)
