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 = int.Parse(Console.ReadLine());

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

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

            for (var i = 0; i < Q; i++)
            {
                var bc = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

                var sum = (ulong)0;

                for (var j = 0; j < As.Count(); j++)
                {
                    As.OrderBy(x => x);

                    var a = As.BinarySearch(bc[0]);

                    if (As.Contains(bc[0]))
                    {
                        if (As[j] == bc[0])
                        {
                            As[j] = bc[1];
                        }
                    }
                    sum += (ulong)As[j];
                }

                Console.WriteLine(sum.ToString());

            }
        }
    }
}
