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

for i in range(Q):
    A = [C[i] if j == B[i] else j for j in A]
    print(sum(A))


