n=int(input())
num=list(map(int,input().split()))
add=sum(num)
q=int(input())
for i in range(q):
    cnt=0
    b,c=map(int,input().split())
    num.sort()
    for i in range(len(num)):
        if num[i]==b:
            num[i]=c
            cnt+=1
        elif num[i]>b:
            break
    add+=(c-b)*cnt
    print(add)