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());

            int[] count = new int[10000000];

            for(int i = 0; i < A.Length; i++)
            {
                count[A[i]]++;
            }

            long answer = A.Sum();

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

                answer += ((BC[1] - BC[0]) * count[BC[0]]);

                Console.WriteLine(answer);

                count[BC[1]] += count[BC[0]];

                count[BC[0]] = 0;
            }
        }
    }
}