import numpy as np

N = int(input())

A_list = list(map(int, input().split()))
A_array = np.array(A_list)

Q = int(input())

for N in range(Q):
    B, C = map(int, input().split())
    if B in A_array:
        A_array[A_array == B] = C
    print(np.sum(A_array))