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(long.Parse).OrderBy(x => x).ToList();
            var q = int.Parse(ReadLine());
            var bLine = new List<int>();
            var cLine = new List<int>();
            for (var i = 0; i < q; i++)
            {
                var bc = ReadLine().Split(' ').Select(int.Parse);
                for (var j = 0; j < aList.Count; j++)
                {
                    if (aList[j] == bc.First())
                    {
                        aList[j] = bc.Last();
                    }
                }

                WriteLine(aList.Sum());
            }
        }
    }
}