# -*- coding: utf-8 -*-
import collections
N = int(input())
A = list(map(int, input().split()))
A_amount = collections.Counter(A)

result = sum(A)

Q = int(input())
for q in range(Q):
    B, C = map(int, input().split())
	B_elem = A_amount.get(B, None)
    if B_elem is not None:
        C_elem = A_amount.get(C, None)
        if C_elem is not None:
            A_amount.pop(B_elem)
            A_amount[C] = (C, B_elem[1]+C_elem[1])
        else:
            A_amount.pop(B_elem)
            A_amount[C] = (C, B_elem[1])

        result += (C-B)*B_elem[1]
        
    print(result)