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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();

            var numsDic = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
            var total = numsDic.Sum(kvp => kvp.Key * kvp.Value);

            var q = int.Parse(Console.ReadLine());
            var list = new List<int>();
            for (var i = 0; i < q; i++)
            {
                var bc = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
                var b = bc[0];
                var c = bc[1];

                if (!numsDic.TryGetValue(b, out _))
                {
                    list.Add(total);
                    continue;
                }
                var sa = c - b;
                total += numsDic[b] * sa;
                list.Add(total);
                if (numsDic.TryGetValue(c, out var val))
                {
                    numsDic[c] += numsDic[b];
                }
                else
                {
                    numsDic.Add(c, numsDic[b]);
                }
                numsDic[b] = 0;
            }

            for (var i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }
        }
    }
}