N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
dic = {}
for i in range(N):
    if A[i] not in dic:
        dic[A[i]] = 1
    else:
        dic[A[i]] += 1;
for i in range(Q):
    B, C = map(int, input().split())
    if B in dic:
        #print(dic)
        j = dic[B]
        dic.pop(B)
        if C in dic:
            dic[C] += j
        else :
            dic[C] = j;
        #print(dic)
    
    summ = 0;
    for item in dic:
        summ += item*dic[item]
    print(summ)
    
