from collections import deque, Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = deque()
for _ in range(Q):
    b, c = map(int, input().split())
    L.append([b, c])
d = [0] * 10**5
count = Counter(A)
sum_a = sum(A)
for j in range(Q):
    d[L[j][1]] = count[L[j][0]]

    sum_a -= d[L[j][1]] * L[j][0]
    sum_a += d[L[j][1]] * L[j][1]

    print(sum_a)
