using System;
using System.Linq;
using System.Text;

namespace _171_d
{
    internal class Replacing
    {
        private static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
            var a = ReadLineIntArray(n);
            var q = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

            for (var i = 0; i < q; i++)
            {
                const int readCharacters = 2;
                var bcLine = ReadLineIntArray(readCharacters);
                var b = bcLine[0];
                var c = bcLine[1];

                var num = Array.IndexOf(a, b, 0);
                while (num >= 0)
                {
                    a[num] = c;
                    num = Array.IndexOf(a, b, num + 1);
                }

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

        private static int[] ReadLineIntArray(int size)
        {
            var sb = new StringBuilder();
            while (true)
            {
                var ch = Convert.ToChar(Console.Read());
                sb.Append(ch);
                if (ch == '\n')
                {
                    break;
                }
            }
            var array = sb.ToString().Split(" ").Select(int.Parse).ToArray();
            return array;
        }
    }
}