N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for _ in range(Q):
    B.append(list(map(int,input().split())))
s=sum(A)
from collections import Counter
a=Counter(A)
b=list(a.keys())
c=list(a.values())
for i in range(Q):
    for j in range(len(set(A))):
        if b[j]==B[i][0]:
            s-=b[j]*c[j]
            s+=B[i][1]*c[j]
    print(s)