N = int(input())
A = list(map(int, input().split()))
Q = int(input())
 
 
for i in range(Q):
    B, C = map(int, input().split())
 
    while(1):
        try:
            A[A.index(B)] = C
        except ValueError:
            break
 
    print(sum(A))