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

namespace Atcoder171
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var As = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var Q = int.Parse(Console.ReadLine());
            var BCs = new List<int[]>();

            for (var i=0;i<Q;i++)
            {
                //BCs.Add(Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray());

                var BS = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                //foreach (var a in As)
                //{
                //    if (a == BS[0]) a = BS[1];
                //}



                var cnt = As.Where(x => x == BS[0]).Count();

                As = As.Where(x => x != BS[0]).Select(x => x).ToList();

                for(var j = 0; j < cnt; j++)
                {
                    As.Add(BS[1]);

                }

                Console.WriteLine(As.Sum());
            }


        }
    }
}