using System;
using System.Collections.Generic;
using System.Linq;


class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] A = new int[100000];
        string[] In = Console.ReadLine().Trim().Split(' ');
        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            A[int.Parse(In[i])]++;
            sum += int.Parse(In[i]);
        }
        int q = int.Parse(Console.ReadLine());
        var que = new Queue<long>();
        for (int i = 0; i < q; i++)
        {
            string[] In2 = Console.ReadLine().Split(' ');
            int b = int.Parse(In2[0]);
            int c = int.Parse(In2[1]);
            int 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());
        }
    }
}

