#Replacing
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())

for i in range(Q):
    B, C = list(map(int, input().split()))
    A = A*( (A==B)==False ) + C*(A==B)
    print(A.sum())