N = int(input())	
A_list = list(map(int,input().split()))
Q = int(input())
BC_dic = [list(map(int,input().split())) for i in range(Q)]
for BC in BC_dic:
    A_list = [BC[1] if A == BC[0] else A for A in A_list]
    print(sum(A_list))