N = int(input())
A = list(map(int, input().strip().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q

for i in range(Q):
    B[i],C[i] = map(int,input().split())

for i in range(Q):
    A = list(map(lambda x: C[i] if x == B[i] else x, A))
    print(sum(A))