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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var numLine = GetConsoleLong(GetConsole().First()).ToArray();
            var opeCount = GetConsole().First();
            var operations = Enumerable.Repeat(0, opeCount).Select(x => GetConsole()).ToArray();

            var operationResult = new List<long>();
            foreach (var operation in operations)
            {
                var ope = operation.ToArray();
                for (int i = 0; i < numLine.Length; i++)
                {
                    if (numLine[i] == ope[0])
                    {
                        numLine[i] = ope[1];
                    }
                }
                operationResult.Add(numLine.Sum());
            }
            OutAllLine(operationResult.Select(x => x.ToString()));
        }

        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;
        }

        private static void OutAllLine(IEnumerable<dynamic> items)
        {
            var sb = new StringBuilder();
            foreach (var result in items)
            {
                sb.Append(result + "\n");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb);
        }
    }
}