N = int(input())
A = list(map(int, input().split()))

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0
    
for i in range(N):
    lst[A[i]] += 1

Q = int(input())

ans = []
for i in range(Q):
    B, C = map(int, input().split())
    if B in lst:
        if C in lst:
            lst[C] += lst[B]
            lst.pop(B)
        else:
            lst[C] = lst[B]
            lst.pop(B)
            
        ans_tmp = 0
        for i in lst:
            ans_tmp += i*lst[i]

        ans.append(ans_tmp)
        
    elif i != 0:
        ans.append(ans[-1])
    else:
        ans_tmp = 0
        for i in lst:
            ans_tmp += i*lst[i]
        ans.append(ans_tmp)

for i in ans:
    print(i)