N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = list(map(int, input().split()))
    if B not in A:
        print(sum_)
        continue
    sum_ = 0
    for j in range(len(A)):
        if A[j] == B:
            A[j] = C
        sum_ += A[j]
    print(sum_)