using System;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToArray();
            Array.Sort(A);
            int Q = int.Parse(Console.ReadLine());
            long[,] BC = new long[Q,2];
            for (int i = 0; i < Q; i++)
            {
                int[] s = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
                BC[i, 0] = s[0];
                BC[i, 1] = s[1];
            }
            for (int i = 0; i < Q; i++)
            {
                bool t = true;
                while (t)
                {
                    int k = Array.BinarySearch(A, BC[i, 0]);
                    if (k >= 0)
                    {
                        A[k] = BC[i, 1];
                        Array.Sort(A);
                    }
                    else
                    {
                        t = false;
                    }
                }
                Console.WriteLine(A.Sum());
            }
        }
    }
}
