using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPractice
{
    class Replacing
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            ulong[] a = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
            var q = int.Parse(Console.ReadLine());
            uint[,] bc = new uint[q,2];
            ulong sum = 0;
            uint[] num = new uint[10001];

            for(int i = 0; i < q; i++)
            {
                var input = Console.ReadLine().Split();
                bc[i, 0] = uint.Parse(input[0]);
                bc[i, 1] = uint.Parse(input[1]);
            }

            foreach(var x in a)
            {
                num[x]++;
                sum += x;
            }

            for(int i = 0; i < q; i++)
            {
                sum += (ulong)((bc[i, 1]- bc[i, 0]) * num[bc[i, 0]]);;
                num[bc[i, 1]] += num[bc[i, 0]];
                num[bc[i, 0]] -= num[bc[i, 0]];
                Console.WriteLine(sum);
            }
        }
    }
}
