import numpy as np

N = int(input())
arr = np.array(list(map(int, input().split())))

Q = int(input())

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