def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return None

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):
    A.sort()
    id = binary_search(A,B[i])
    if id != None:
        A[id] = C[i]
        r = id + 1
        l = id - 1
        while A[r] == B[i]:
            A[r] = C[i]
            r += 1
            if r == N:
                break
        while A[l] == B[i]:
            A[l] = C[i]
            l -= 1
            if l == -1:
                break
    print(sum(A))