from collections import Counter
n = int(input())

L = list(map(int,input().split()))
sum_all = sum(L)
L = Counter(L)
#print(L)
q = int(input())
sum1 = sum_all
for i in range(q):
    
    a,b = map(int,input().split())
    #print(L)
    if a not in L:
        L[b] = 0
    else:
        L[b] +=L[a] 
    #print(L)
    sum1 = sum1 + b*L[a] - a*L[a]
    #L[a] =0
    
    #print(L)
    print(sum1)