N = int(input())	
A_list = list(map(int,input().split()))
Q = int(input())
result = []
for i in range(Q):
        B, C = map(int,input().split())
        A_list = [C if A == B else A for A in A_list]
        print(sum(A_list)
