using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class ABC171D2
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            string line;
            string[] sa;
            line = Console.ReadLine();
            int N = int.Parse(line);

            line = Console.ReadLine();
            sa = line.Split(' ');
            Dictionary<long, long[]> dic = new Dictionary<long, long[]>();
            for (int i = 0; i < N; ++i)
            {
                long a = long.Parse(sa[i]);

                if (dic.ContainsKey(a))
                {
                    dic[a][0] += 1;
                    dic[a][1] += a;
                }
                else
                {
                    long[] la = new long[2];
                    la[0] = 1;
                    la[1] = a;
                    dic[a] = la;
                }
            }


            line = Console.ReadLine();
            int Q = int.Parse(line);

//            int[,] BC = new int[Q, 2];
//            Dictionary<int, int> cnvDic = new Dictionary<int, int>();
//            Dictionary<int, int> cnvDicReverse = new Dictionary<int, int>();
            for (int i = 0; i < Q; ++i)
            {
                line = Console.ReadLine();
                sa = line.Split(' ');
                long b = long.Parse(sa[0]);
                long c = long.Parse(sa[1]);

                if (dic.ContainsKey(b))
                {
                    long[] ba = dic[b];
                    dic.Remove(b);
                    if (dic.ContainsKey(c))
                    {
                        long[] ca = dic[c];
                        ca[0] += ba[0];
                        ca[1] += c * ba[0];
                    }
                    else
                    {
                        ba[1] = c * ba[0];
                        dic[c] = ba;
                    }
                }
                Console.WriteLine(sum(dic));
            }


#if DEBUG
            Console.WriteLine("*** end ***");
            Console.SetIn(Console.In);
            Console.ReadKey();
#endif
        }

        public static string    sum(Dictionary<long, long[]> dic)
        {
            long result = 0;
            foreach(var d in dic)
            {
                result += d.Value[1];
            }
            return result.ToString();
        }
    }
}
