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

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        var q = int.Parse(ReadLine());
        int[] w = new int[100001];
        long l = 0;
        for(int i = 0; i < n; i++)
        {
            w[a[i]]++;
            l += a[i];
        }
        for(int i = 0; i < q; i++)
        {
            var b = ReadLine().Split().Select(int.Parse).ToArray();
            for(int j = 0; j < n; j++)
            {
                l += (long)(b[1] - b[0]) * w[b[0]];
                w[b[1]] += w[b[0]];
                w[b[0]] = 0;
            }
            WriteLine(l);
        }
    }
}
