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

namespace CodeForcesPractice
{
    class Program
    {
        //public static string[] SplitInput(string Line,int NumParam)
        //{
        //    string[] RetArr = new string[NumParam];
        //    RetArr = Line.Split(' ');
        //    return RetArr;
        //}
        public static int[] IntInput(string Line, int NumParam)
        {
            string[] RetArr = new string[NumParam];
            RetArr = Line.Split(' ');
            int[] arr = new int[NumParam];
            for (int i = 0; i < NumParam; i++)
            {
                arr[i] = Convert.ToInt32(RetArr[i]);
            }
            return arr;
        }
        
        public static void Replacing()
        {
            int arrLen = Convert.ToInt16(Console.ReadLine());
            int[] nums = IntInput(Console.ReadLine(), arrLen);
            int cases = Convert.ToInt16(Console.ReadLine());
            int l = nums.Length;
            for (int i = 0; i < cases; i++) {
                Int64 sum = 0;
                int[] arr2 = new int [l];
                Array.Copy(nums, arr2,l);
                int[] arr = IntInput(Console.ReadLine(), 2);
                int j = arr[0];
                int k = arr[1];
                for (int q = 0; q < l; q++)
                {
                    if (arr2[q] == j) { arr2[q] = k; }
                    sum += arr2[q];
                }
                Console.WriteLine(sum);
            }
        }
        static void Main(string[] args)
        {
            Replacing();
            Console.ReadLine();
        }
    }
}
