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

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);

            int Q = int.Parse(Console.ReadLine());

            List<int[]> BC = new List<int[]>();

            int[] count = new int[Q];

            for(int i = 0; i < Q; i++)
            {
                BC.Add(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
            }

            for (int i = 0; i < Q; i++)
            {

                long answer = 0;

                for (int j = 0; j < A.Length; j++)
                {
                    if(A[j] == BC[i][0])
                    {
                        A[j] = BC[i][1];
                    }

                    answer += A[j];
                }

                Console.WriteLine(answer);
            }
        }
    }
}