using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            var q = Read();
            var d = new long[(long)Math.Pow(10, 5)];
            for (int i = 0; i < n; i++)
            {
                d[a[i]]++;       
            }
            long ans = a.Sum();
            for (int i = 0; i < q; i++)
            {
                var bc = Reads();
                ans += (bc[1] - bc[0]) * d[bc[0]];
                d[bc[1]] += d[bc[0]];
                d[bc[0]] = 0;             
                WriteLine(ans);
            }
          
            Console.Out.Flush();
        }
    }
}

