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

class Program
{
    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());

        var array = Console.ReadLine().Split(' ');

        var Q = long.Parse(Console.ReadLine());

        var dict = new Dictionary<long, long>();

        for(long i = 1; i< 100000; i++)
        {
            dict.Add(i, 0);
        }

        long sum = 0;

        foreach (var n in array)
        {
            dict[long.Parse(n)] += 1;
            sum += long.Parse(n);
        }

        for(long i = 0; i < Q; i++)
        {
            var nums = Console.ReadLine().Split(' ');
            var b = long.Parse(nums[0]);
            var c = long.Parse(nums[1]);

            var count = dict[b];
            var minus = count * b;
            var plus = count * c;
            sum = sum - minus + plus;            

            dict[b] = 0;
            dict[c] += count;

            Console.WriteLine(sum);
        }



 
        Console.ReadLine();

    }
}