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

for i in range(Q):
    B, C = map(int, input().split())
    for j in range(N):
        if newA[j] == B:
            newA[j] = C
        if newA[j] > C:
            break
    print(sum(newA))