N = int(input())
A = sorted(list(map(int, input().split())))
Q = int(input())
BL = []
CL = []
for _ in range(Q):
    B, C = map(int, input().split())
    BL.append(B)
    CL.append(C)

for i in range(Q):
    for j in range(N):
        if A[j] > BL[i]:
            break
        elif A[j] == BL[i]:
            A[j] = CL[i]
    print(sum(A))
    A = sorted(A)