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

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

     public static void hoge()
    {
        var n = long.Parse(System.Console.ReadLine());
        var a = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var vlst = new Dictionary<long, long>();
        foreach(var v in a)
        {
            if (vlst.ContainsKey(v))
            {
                vlst[v]++;
            }
            else
            {
                vlst.Add(v, 1);
            }
        }
        var q = long.Parse(System.Console.ReadLine());

        var sum = a.Sum();
        var query = a.AsEnumerable();
        Dictionary<long, long> dic = new Dictionary<long, long>();

        for(long i = 0; i < q; i++)
        {
            var var = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var b = var[0];
            var c = var[1];
            var sa = c - b;
            sa *= vlst[b];
            sum += sa;
            Console.WriteLine(sum);
            if (!vlst.ContainsKey(c))
            {
                vlst.Add(c, 0);
            }
            vlst[c] += vlst[b];
            vlst[b] = 0;
        }

    }
}