N = int(input())

A = input().split()
A = [int(c) for c in A]

Q = int(input())

i = 1

B = []
C = []

for i in range(Q):
    b,c = input().split()
    B.append(int(b))
    C.append(int(c))

for j in range(Q):
    count = A.count(B[j])
    for h in range(count):
        A.remove(B[j])
    C1 = [C[j]] * count
    A.extend(C1)
    print(sum(A))