using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var numLine = GetConsole(GetConsole().First()).ToArray();
            var operations = new List<int[]> { };
            var opeCount = GetConsole().First();
            for (int i = 0; i < opeCount; i++)
            {
                operations.Add(GetConsole().ToArray());
            }

            foreach (var operation in operations)
            {
                var notTarget = numLine.Where(x => x != operation[0]);
                var operated = numLine.Where(x => x == operation[0]).Select(x => operation[1]);
                numLine = notTarget.Concat(operated).ToArray();
                Console.WriteLine(numLine.Sum());
            }
        }

        private static IEnumerable<int> GetConsole(int count = 0)
        {
            var console = Console.ReadLine().Split(' ').Select(int.Parse);
            return count != 0 ? console.Take(count) : console;
        }
    }
}