n = int(input())
a = list(map(int, input().split()))
q = int(input())
x = sum(a)
ans = [0]*q
for i in range(q):
    b, c = map(int, input().split())
    num_b = a.count(b)
    x -= num_b * b
    x += num_b * c
    ans[i] = x
for i in range(q):
    print(ans[i])
