N = input()
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for j in range(Q):
    B[j], C[j] = map(int, input().split())
for k in range(Q):
    A = [C[k] if i == B[k] else i for i in A]
    print(sum(A))