using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var n = Sarray()[0];
            var tmp = Sarray();
            var an = new Dictionary<long, long>();
            var q = Sarray()[0];
            var bcn = new Dictionary<long, long>();
            var anss = new List<long>();
            for (var i = 0; i < tmp.Length; i++)
            {
                if (an.ContainsKey(tmp[i])) an[tmp[i]]++;
                else an.Add(tmp[i], 1);
            }
            for (var i=0;i<q;i++)
            {
                var bc = Sarray();
                bcn.Add(bc[0], bc[1]);
            }
            long ans = 0;
            foreach(var item in an)
            {
                ans += item.Key * item.Value;
            }
            foreach(var item in bcn)
            {
                if(an.ContainsKey(item.Key))
                {
                    ans += (item.Value - item.Key) * an[item.Key];
                    if (an.ContainsKey(item.Value)) an[item.Value] += an[item.Key];
                    else an.Add(item.Value, an[item.Key]);
                    an[item.Key] = 0;
                }
                anss.Add(ans);
            }
            foreach (var item in anss)
            {
                WriteLine(item);
            }
        }
    }
}
