N = int(input())
list_A = [int(item) for item in input().split()]
Q = int(input())
list_bc = []
for i in range(Q):
    list_bc.append([int(item) for item in input().split()])

for i in range(Q):
    B = list_bc[i][0]
    C = list_bc[i][1]
    # list_A = [C if item == B else item for item in list_A]
    while(B in list_A):
        index = list_A.index(B)
        list_A[index] = C
    print(sum(list_A))