N = int(input())
A = list(map(int, input().split()))
Q = int(input())

for q in range(Q):
    B, C = list(map(int, input().split()))
    
    count= A.count(B)
    for n in range(count):
        index = A.index(B)
        A[index] = C
    print(sum(A))