import numpy as np

def resolve():
    n = int(input())
    A = np.array(list(map(int, input().split())))
    q = int(input())
    bc = []
    for _ in range(q):
        bc.append(list(map(int, input().split())))
    bc = np.array(bc)
    
    for i in range(q):
        A = np.where(A == bc[i][0], bc[i][1], A)
        print(np.sum(A))
        
resolve()
