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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var numLine = GetConsoleLong(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)
            {
                for (int i = 0; i < numLine.Length; i++)
                {
                    if (numLine[i] == operation[0])
                    {
                        numLine[i] = operation[1];
                    }
                }
                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;
        }
        
        private static IEnumerable<long> GetConsoleLong(int count = 0)
        {
            var console = Console.ReadLine().Split(' ').Select(long.Parse);
            return count != 0 ? console.Take(count) : console;
        }
    }
}