import numpy as np

N = int(input())
A = np.array(sorted(list(map(int, input().split()))))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())
    A[A==B[i]] = C[i]
    print(np.sum(A))