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

namespace ABC0613
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<long> inp = Console.ReadLine().Split(" ").Select(long.Parse).ToList();
            int q = int.Parse(Console.ReadLine());
            List<long> ans = new List<long>();
            int b = 0;
            long c = 0;
            for (int i = 0; i < q; i++)
            {
                string[] str = Console.ReadLine().Split(" ");
                b = int.Parse(str[0]); c = int.Parse(str[1]);
                if (inp.Contains(b))
                {
                    var ic = inp.Where(hogege => hogege == b).Count();
                    var hoge = inp.Where(hogege => hogege != b).ToList();
                    ans.Add(ic * c + hoge.Sum());
                    inp = new List<long>();
                    inp = Enumerable.Repeat(c, ic).ToList();
                    inp.AddRange(hoge);
                }
                else
                {
                    ans.Add(inp.Sum());
                }
                
            }
            foreach (long s in ans)
            {
                Console.WriteLine(s);
            }
        }
    }
}
