using System;
using System.Linq;
using static System.Console;

namespace ConsoleAppAtCoderABC171
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var a = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            var q = int.Parse(ReadLine());

            for(int i = 0; i < q; i++)
            {
                var bc = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

                for (int j = 0; j < n; j++)
                {
                    if(a[j] == bc[0])
                    {
                        a[j] = bc[1];
                    }
                }

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