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

b = []
c = []

A.sort()

for i in range(Q):
    B, C = map(int, input().split())
    b.append(B)
    c.append(C)

for i in range(Q):
    if b[i] in A:
        for j in range(len(A)):
            if A[j] == b[i]:
                A[j] += c[i]-b[i]
            else:
                continue
    print(sum(A))
