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

namespace ConsoleApp2
{
    class Program
    {
        static void Main()
        {
            var a = int.Parse(Console.ReadLine());
            var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x =>x).ToArray();
            var Q = int.Parse(Console.ReadLine());

            var b = new int[Q];
            var c = new int[Q];
            
            
            for (int i = 0; i < Q; i++)
            {
                int ans = 0;
                int random = 0;
                var z = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                b[i] = z[0];
                c[i] = z[1];


                foreach (var m in X)
                {
                    if (m == b[i])
                    {
                        X[random] = c[i];
                    }
                    random++;
                }

                for (int k = 0; k < X.Count(); k++)
                {
                    ans += X[k];
                }

                Console.WriteLine(ans);
            }
        }
    }
}
