#d
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())
for i in range(Q):
    for j in range(A.count(B[i])):
        youso=A.index(B[i])
        A[youso]=C[i]
    print(sum(A))