N = int(input())
A = list(map(int, input().split()))
Q = int(input())
dis_list = []
for i in range(Q):
    s = list(map(int, input().split()))
    dis_list.append(s)
for j in range(len(dis_list)):
    for k in range(len(A)):
        if A[k] == dis_list[j][0]:
            A[k] = dis_list[j][1]
    print(sum(A))