using System;
using System.Linq;
using System.Collections.Generic;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var Q = int.Parse(Console.ReadLine());
            
            var arr = new long[100000];
            foreach(var A in As)
            {
                arr[A] ++;
            }
            var sum = As.Sum();


            for (int i = 0; i < Q; i++)
            {
                var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
                sum += (input[1] - input[0]) * arr[input[0]];
                arr[input[1]] += arr[input[0]];
                arr[input[0]] = 0;
                Console.WriteLine(sum);
            }
        }
    }
}
