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

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

            long sum = 0;
            for(var i = 1; i <= 10001; i++)
            {
                sum += arr[i] * i; 
            }

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