B = list()
C = list()
int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    bb, cc= map(int, input().split())
    B.append(bb)
    C.append(cc)
for i,j in enumerate(range(Q)):    
    A = [C[i] if k == B[i] else k for k in A]
    print(sum(A))

