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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int total = 0;
            Dictionary<int, int> numdict = new Dictionary<int, int> { };

            for (int i = 0; i < n; i++)
            {
                int thisnum = input[i];
                total += thisnum;
                if (numdict.ContainsKey(thisnum))
                    numdict[thisnum]++;
                else
                    numdict.Add(thisnum, 1);
            }

            int q = int.Parse(Console.ReadLine());

            var b = new int[q];
            var c = new int[q];

            for (int i = 0; i < q; i++)
            {
                var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
                b[i] = input1[0];
                c[i] = input1[1];
            }

            for (int i = 0; i < q; i++)
            {
                if (numdict.ContainsKey(b[i]))
                {
                    if (numdict.ContainsKey(c[i]))
                    {
                        total += numdict[b[i]] * (c[i] - b[i]);
                        numdict[c[i]] += numdict[b[i]];
                        numdict[b[i]] = 0;
                    }
                    else
                    {
                        total += numdict[b[i]] * (c[i] - b[i]);
                        numdict.Add(c[i], numdict[b[i]]);
                        numdict[b[i]] = 0;
                    }
                }
                Console.WriteLine(total);
            }

        }

    }
}
