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<long, long>();
            foreach (var a in aList)
            {
                if (aTable.ContainsKey(a))
                {
                    ++aTable[a];
                }
                else
                {
                    aTable.Add(a, 1);
                }
            }

            var firstTotal = Total(aTable);
            var currentTotal = firstTotal;

            var q = int.Parse(Console.ReadLine());
            var queryList = new List<KeyValuePair<long, long>>();
            for (var i = 0; i < q; ++i)
            {
                var bc = Console.ReadLine().Split(' ');
                var kv = new KeyValuePair<long, long>(long.Parse(bc[0]), long.Parse(bc[1]));
                queryList.Add(kv);
            }

            for (var i = 0; i < q; ++i)
            {
                var b = queryList[i].Key;
                var c = queryList[i].Value;
                var diff = 0L;
                if (aTable.ContainsKey(b))
                {
                    diff = (c - b) * aTable[b];
                    if (aTable.ContainsKey(c))
                    {
                        aTable[c] += aTable[b];
                    }
                    else
                    {
                        aTable[c] = aTable[b];
                    }
                    aTable.Remove(b);
                    currentTotal += diff;
                    Console.WriteLine(currentTotal);
                }
            }
        }
        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 long Total(Dictionary<long, long> aTable)
        {
            var total = 0L;
            foreach (var kv in aTable)
            {
                total += kv.Key * kv.Value;
            }
            return total;
        }
    }
}
