n=int(input())
l=list(map(int,input().split()))
q=int(input())
before=[]
after=[]
for i in range(q):
    a,b=input().split()
    before.append(int(a))
    after.append(int(b))
    
su=sum(l)

for i in range(q):
  if before[i] in l:
    co=l.count(before[i])
    su=su+(after[i]-before[i])*co
    print(su)
