n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    x=sum(a)
    p=0
    for i in range(len(a)):
        y=a[i]
        if y==b:
            a[i]=c
            p+=1
    print(x+(c-b)*p)