using System;
using System.Collections.Generic;

namespace abc171
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var aList = ReadNumList();
            var aTable = new Dictionary<int, int>();
            foreach (var a in aList)
            {
                if (aTable.ContainsKey(a))
                {
                    ++aTable[a];
                }
                else
                {
                    aTable.Add(a, 1);
                }
            }

            var q = int.Parse(Console.ReadLine());
            var queryList = new List<KeyValuePair<int, int>>();
            for (var i = 0; i < q; ++i)
            {
                var bc = Console.ReadLine().Split(' ');
                var kv = new KeyValuePair<int, int>(int.Parse(bc[0]), int.Parse(bc[1]));
                queryList.Add(kv);
            }
            for (var i = 0; i < q; ++i)
            {
                var b = queryList[i].Key;
                var c = queryList[i].Value;
                if (aTable.ContainsKey(b))
                {
                    if (aTable.ContainsKey(c))
                    {
                        aTable[c] += aTable[b];
                    }
                    else
                    {
                        aTable[c] = aTable[b];
                    }
                    aTable.Remove(b);
                }
                Output(aTable);
            }
        }
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Output(Dictionary<int, int> aTable)
        {
            var total = 0L;
            foreach (var kv in aTable)
            {
                total += (long)kv.Key * kv.Value;
            }
            Console.WriteLine(total);
        }
    }
}
