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

s = sum(A)
for i in range(0, Q):
    count = A.count(B[i])
    A = [j for j in A if j != B[i]]
    for _ in range(count):
        A.append(C[i])
    print(sum(A))