N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC=[]
for i in range (0, Q):
    BC.append([int(i) for i in input().split()])
"""
for bc in BC:
    bc = [int(i) for i in bc]
"""
#print(BC)
sum = sum(A)
for bc in BC:
    count = 0
    for i in range(0,len(A)):
        if A[i] == bc[0]:
            A[i] = bc[1]
            count += 1
  #  print("A:",A)
    sum += (bc[1]-bc[0])*count
    print (sum)