import numpy as np
from numba import jit

N = int(input())
A = np.asarray(list(map(int, input().split())))
Q = int(input())
B, C = np.zeros(Q, dtype=np.int64), np.zeros(Q, dtype=np.int64)
for i in range(Q):
    [b, c] = list(map(int, input().split()))
    B[i], C[i] = b, c
    
@jit(nopython=True)
def calc(A, B, C, Q):
    for i in range(Q):
        A = np.where(A==B[i], C[i], A)
        print(np.sum(A))

calc(A, B, C, Q)
