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

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var N = c2i(RL());
            var Ax = RL2IE().ToList();
            var Q = c2i(RL());
            var BCx = new List<Tuple<int, int>>();
            long sum = 0;
            var ret = new List<long>();
            foreach (var a in Ax)
            {
                sum += a;
            }

            for (int i = 0; i < Q; i++)
            {
                var BC=RL2IE();
                var ch=BC.First();
                for (int k = 0; k < N; k++)
                {
                    if (Ax[k] == ch)
                    {
                        var num = BC.Last();
                        sum = sum - ch + num;
                        Ax[k] = num;
                    }
                }
                ret.Add(sum);
                    //BCx.Add(new Tuple<int, int>((int)BC.First(), (int)BC.Last()));
            }

            foreach (var a in ret)
            {
                Console.WriteLine(a);

            }
                
            //Console.WriteLine(sum);
            Console.ReadLine();

        }

        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}
