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

namespace AtCoder.ABC171
{
    public class Problem4
    {
        public static void Main(string[] args)
        {
            var N = ulong.Parse(Console.ReadLine());

            var As = Console.ReadLine().Split(" ").Select(x => ulong.Parse(x)).ToList();

            var Q = ulong.Parse(Console.ReadLine());

            var BCs = new List<List<ulong>>();

            for (var i = (ulong)0; i < Q; i++)
            {
                var bc = Console.ReadLine().Split(" ").Select(x => ulong.Parse(x)).ToArray();
                BCs.Add(new List<ulong> { bc[0], bc[1] });
            }

            for (var i = (ulong)0; i < Q; i++)
            {
                var sum = (ulong)0;

                for (var j = (ulong)0; j < (ulong)As.Count(); j++)
                {
                    if (As[(int)j] == BCs[(int)i][0])
                    {
                        As[(int)j] = BCs[(int)i][1];
                    }
                    sum += As[(int)j];
                }

                Console.WriteLine(sum.ToString());
            }
        }
    }
}
