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()]

    for j in range(len(A)):
        if m == A[j]:
            A[j] = n
    array.append(sum(A))
for i in array:
    print(i)
