namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Reflection.PortableExecutable;
    using System.Runtime.CompilerServices;
    using System.Text;
    using System.Threading;
    using System.Xml.Serialization;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var N = int.Parse(Console.ReadLine());
            var A = t.ParseIntList(t.ReadInput());
            var Q = int.Parse(Console.ReadLine());
            var dic = new Dictionary<int, int>(100000);
            var ansList = new List<long>();


            for (var i = 1; i <= 100000; i++)
            {
                dic.Add(i, 0);
            }

            for (var i = 0; i < N; i++)
            {
                dic[A[i]]++;
            }

            for (var i = 0; i < Q; i++)
            {
                var bc = t.ParseIntList(t.ReadInput());

                if (dic[bc[0]] >= 1)
                {
                    dic[bc[1]] += dic[bc[0]];
                    dic[bc[0]] = 0;
                }

                ansList.Add(t.Sum(dic));
            }

            foreach (var ans in ansList)
            {
                Console.WriteLine(ans);
            }

        }

        public long Sum(Dictionary<int, int> dic)
        {
            long temp = 0;
            foreach (var d in dic)
            {
                temp += d.Key * d.Value;
            }

            return temp;
        }

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ParseIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }


        public List<double> ParseDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ParseLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}