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();
            Dictionary<long,long> dict = new Dictionary<long, long>();
            foreach(var A in As)
            {
                if(dict.Keys.Any(x => x == A))
                {
                    dict[A] += 1;
                }
                else
                {
                    dict.Add(A, 1);
                }
            }

            long sum = 0;
            foreach(var key in dict.Keys)
            {
                sum += dict[key] * key; 
            }

            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 (!dict.ContainsKey(b))
                {
                    result.Add(sum);
                    continue;
                }
                
                var val = dict[b];
                if(dict.Keys.Any(x => x == c))
                {
                    dict[c] += val;
                }
                else
                {
                    dict.Add(c, val);
                }
                dict.Remove(b);
                sum += (c * val) - (b * val);
                result.Add(sum);
            }
            result.ForEach(x => Console.WriteLine(x.ToString()));
        }
    }
}
