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

namespace ABC
{
    class ABC171D
    {
        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(' ');
            int[] A = new int[N];
            Dictionary<int, int> dic = new Dictionary<int, int>();
            for (int i = 0; i < N; ++i)
            {
                int a = int.Parse(sa[i]);
                A[i] = a;

                if (dic.ContainsKey(a))
                {
                    dic[a] += 1;
                }
                else
                {
                    dic[a] = 1;
                }
            }


            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(' ');
                int b = int.Parse(sa[0]);
                int c = int.Parse(sa[1]);

                if (dic.ContainsKey(b))
                {
                    int count = dic[b];
                    dic.Remove(b);
                    if (dic.ContainsKey(c))
                    {
                        dic[c] += count;
                    }
                    else
                    {
                        dic[c] = count;
                    }
                }
                Console.WriteLine(sum(dic));
            }


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

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