from collections import Counter

N = int(input())
data = list(map(int,input().split()))
Q = int(input())
pala = list()
for i in range(Q):
    b = list(map(int,input().split()))
    pala.append(b)

count = Counter(data)

sum = 0
for k , v in count.items():
    sum += (k * v)

for B,C in pala:
    diff = (C - B) * count[B]
    res = sum + diff
    print(res)