n=int(input())
lst=list(map(int,input().strip().split()))[:n]
q=int(input())
i=1
s=sum(lst)
while(i<=q):
    b,c=map(int,input().split())
    count=lst.count(b)
    # print((s+(count*c))-count*b)
    if(count!=0):
        lst = list(filter((b).__ne__, lst))
        lst+=[c]*count
    print(sum(lst))
    i+=1
