import numpy as np
N = int(input())
A = list(map(int,input().split()))	
Q = int(input())
B = [0]*Q
C = [0]*Q
A = np.array(A)

for i in range(Q):
    B[i], C[i] = map(int,input().split())

for i in range(Q):
    A[A==B[i]]=C[i]
    print(np.sum(A))