import numpy as np

n = int(input())
A = list(map(int,input().split()))
q = int(input())
BC = [list(map(int,input().split())) for _ in range(q)]
A = np.array(A)

for bc in BC:
    A = np.where(A==bc[0],bc[1],A)
    print(sum(A))