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

class ABC171
{
    static void Main()
    {
        long num_N = long.Parse(Console.ReadLine());
        long[] aarr = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        long num_Q = long.Parse(Console.ReadLine());

        long[] barr = new long[num_Q];
        long[] carr = new long[num_Q];
        for (int i=0; i<num_Q; i++)
        {
            string[] sarr = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            barr[i] = long.Parse(sarr[0]);
            carr[i] = long.Parse(sarr[1]);
        }

        for (int i = 0; i < num_Q; i++)
        {
            while (true)
            {
                int indexx = Array.IndexOf(aarr, barr[i]);
                if(indexx == -1)
                {
                    break;
                }
                else
                {
                    aarr[indexx] = carr[i];
                }
            }
            Console.WriteLine(aarr.Sum());
            //System.Diagnostics.Debug.WriteLine(aarr.Sum());
        }
    }
}