import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
sum_list = [x * y for (x, y) in dic.items()]
for i in range(q):
    b, c = map(int, input().split())
    print(sum(sum_list) - (b - c) * dic[b])
