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())
A.sort()
j = 0
for i in range(Q):
    while binary_search(A,B[i]) != None:
        id = binary_search(A,B[i])
        if A[id] == B[i]:
            A[id] = C[i]
            A.sort()
    print(sum(A))
