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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToList();
            var q = int.Parse(Console.ReadLine());

            long partialSum = a.Sum();
            var ans = new long[q];

            for (int i = 0; i < q; i++)
            {
                var bc = Console.ReadLine().Split().Select(long.Parse).ToArray();
                var b = bc[0];
                var c = bc[1];

                var count = a.Count(x => x == b);
                a.RemoveAll(x => x == b);
                for(int j = 0; j < count; j++)
                {
                    a.Add(c);
                }

                ans[i] = a.Sum();
            }

            for (int i = 0; i < q; i++) 
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}