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 => int.Parse(x)).ToArray();
            var arr = new int[100002];
            foreach(var A in As)
            {
                arr[A] += 1;
            }
            int sum = As.Sum();

            var Q = int.Parse(Console.ReadLine());
            var result = new List<int>();
            for(var i = 1; i <= Q ; i++)
            {
                var bc = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var b = bc[0];
                var c = bc[1];
                sum += (c - b) *  arr[b];
                arr[c] += arr[b];
                arr[b] = 0;
                Console.WriteLine(sum.ToString());
            }
        }
    }
}
