N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
array = []
for i in range(Q):
    m,n = [int(x) for x in input().split()]
    array.append([m,n])
operation = []
for i in range(len(array)):
    for j in range(len(A)):
        if array[i][0] == A[j]:
            A[j] = array[i][1]
    print(sum(A))
