N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
ans = []
for x in range(Q):
    B, C = [int(x) for x in input().split()]
    N = A.count(B)
    A = list(filter(lambda x: x != B, A))
    A.extend([C] * N)
    ans.append(sum(A))
for x in ans:
    print(x)