import sys
import numpy as np
input = sys.stdin.readline

N=int(input())
A=map(int,input().split())
Q=int(input())
numbers=[]
for _ in range(Q):
    B,C=map(int,input().split())
    numbers.append([B,C])
answers=[0 for _ in range(100001)]
for a in A:
    answers[a]+=a
for number in numbers:
    suuji=answers[number[0]]//number[0]
    answers[number[0]]=0
    answers[number[1]]+=suuji*number[1]

    answer=np.array(answers)
    answer=np.nonzero(answer)
    suuji=0
    for a in answer[0]:
        suuji+=answers[a]
    print(suuji)
    