using System;
using System.Collections.Generic;

namespace ABC171Test
{
    class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine().Trim());
            var buff = Console.ReadLine().Trim().Split(' ');
            List<int> A = new List<int>();
            foreach (var bf in buff) A.Add(int.Parse(bf));

            int Q = int.Parse(Console.ReadLine().Trim());
            List<int> B = new List<int>();
            List<int> C = new List<int>();
            long sum;
            for (int k = 0; k < Q; k++) {
                buff = Console.ReadLine().Trim().Split(' ');
                B.Add(int.Parse(buff[0]));
                C.Add(int.Parse(buff[1]));
            }

            
            for (int i = 0; i < Q; i++) {
                sum = 0;
                for (int l = 0; l < N; l++) {
                    if (A[l] == B[i]) A[l] = C[i];
                    sum += A[l];
                    
                }
                Console.WriteLine(sum);
                sum = 0;
            }

        }


    }

}
