N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    if B[i][0] in a_list:   
        for j in range(N):
            if a_list[j]==B[i][0]:
                a_list[j]=B[i][1]
    print(sum(a_list))