using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;

namespace ABC171
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) {AutoFlush = false};
            SetOut(sw);
            SolveD();
            Out.Flush();
        }


        static void SolveD()
        {
            ReadLine();
            var aList = ReadLine().Split(' ').Select(int.Parse);
            var aDic = new Dictionary<int, int>();
            foreach (var a in aList)
            {
                if (!aDic.ContainsKey(a))
                {
                    aDic.Add(a, 1);
                }
                else
                {
                    aDic[a]++;
                }
            }

            var q = int.Parse(ReadLine());
            for (var i = 0; i < q; i++)
            {
                var bc = ReadLine().Split(' ').Select(int.Parse);
                if (aDic.ContainsKey(bc.First()))
                {
                    var tmp = aDic[bc.First()];
                    aDic.Remove(bc.First());
                    if (!aDic.ContainsKey(bc.Last()))
                    {
                        aDic.Add(bc.Last(), tmp);
                    }
                    else
                    {
                        aDic[bc.Last()]+=tmp;
                    }
                }


                var sum = 0;
                foreach (var a in aDic)
                {
                    sum += a.Key * a.Value;
                }
                WriteLine(sum);
            }
        }
    }
}