using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Console;

namespace CPLib
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int q = int.Parse(ReadLine());
            var sum = 0;
            int[] cnt = new int[(int)1E5+1];
            for (int i = 0; i < n; i++)
            {
                sum += s[i];
                cnt[s[i]]++;
            }
            for (int i = 0; i < q; i++)
            {
                int[] bc = ReadLine().Split(' ').Select(int.Parse).ToArray();
                sum += (bc[1] - bc[0]) * cnt[bc[0]];
                cnt[bc[1]] += cnt[bc[0]];
                cnt[bc[0]] = 0;
                WriteLine(sum);
            }
        }
    }
}
