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

namespace ConsoleApp1
{
    class Program3
    {
        private class Change
        {
            public int before;
            public int after;
        }

        static void Main(string[] args)
        {
            //long n = long.Parse(Console.ReadLine());
            int[] inputLongArray1 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int[] inputLongArray2 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int[] inputLongArray3 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int input = inputLongArray3[0];
            int count = 0;
            var selectList = new List<int>();
            selectList = inputLongArray2.ToList();
            var changeList = new List<Change>();

            while (input > count)
            {
                int[] inputLongArray4 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

                var r = new Change();
                r.before = inputLongArray4[0];
                r.after = inputLongArray4[1];

                changeList.Add(r);

                count++;
            }

            var countList = new List<int>();

            for (var i = 1; i < 100000; i++)
            {
                countList.Add(selectList.Count(x => x == i));
            }

            count = 0;
            string result = string.Empty;
            var sum = selectList.Sum();

            while (input > count)
            {
                var beforenum = changeList[count].before;
                var afternum = changeList[count].after;
                var counter = countList[beforenum - 1];

                sum += counter * (afternum - beforenum);

                countList[beforenum - 1] = 0;
                countList[afternum - 1] += counter;

                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                sw.Write(sum.ToString() + "\n");
                Console.SetOut(sw);
                Console.Out.Flush();
                count++;
            }
        }
    }
}
