using System;
using System.Collections.Generic;
using System.Linq;
{
    static void Main()
    { // by furukori 
        int n = int.Parse(Console.ReadLine());
        uint[] A = new uint[100001];//1にするところ注意
        string[] In = Console.ReadLine().Split(' ');
        //long sum = 0;
        ulong sum = 0;
        for (int i = 0; i < n; i++)
        {
            A[int.Parse(In[i])]++;
            sum += uint.Parse(In[i]);
            //sum += int.Parse(In[i]);
        }
        int q = int.Parse(Console.ReadLine());
        var que = new Queue<ulong>();
        //var que = new Queue<long>();
        for (int i = 0; i < q; i++)
        {
            string[] In2 = Console.ReadLine().Split(' ');
            uint b = uint.Parse(In2[0]);
            uint c = uint.Parse(In2[1]);
            //int temp_num = A[b];
            uint temp_num = A[b];
            sum -= temp_num * b;
            sum += temp_num * c;
            A[b] = 0;
            A[c] += temp_num;
            que.Enqueue(sum);
        }
        while (!(que.Count == 0))
        {
            Console.WriteLine(que.Dequeue());
        }
    }
}