using System;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;

namespace atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int N = int.Parse(input);
            string[] input2 = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            int count = 0;
            int sumcount = 0;

            //A入力
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(input2[i]);
            }
            //Q入力
            string Qinput = Console.ReadLine();
            int Q = int.Parse(Qinput);
            int[] sum = new int[Q];

            for (int j= 0; j < Q; j++)
            {
            string[] BCinput = Console.ReadLine().Split(' ');

            int B = int.Parse(BCinput[0]);
            int C = int.Parse(BCinput[1]);

                while (count <= Q)
                {
                    if (A[count] == B)
                    {
                        A[count] = C;
                    }
                    count++;
                }
                count = 0;

                for(int k = 0; k < N; k++)
                {
                        sum[sumcount] += A[k];
                }
                sumcount++;
             }
            
            for(int p = 0; p < Q; p++)
            {
                Console.WriteLine(sum[p]);
            }
        }
    }
}
