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

q = []

for i in range(Q):
    B, C = list(map(int, input().split()))
    for i in range(N):
        if A[i] > B:
            break
        if A[i] == B:
            A[i] = C

    A.sort()
    q.append(sum(A))

for i in q:
    print(i)