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

namespace contest_Csharp
{
    class Program
    {


        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var vals = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();

            var N = vals[0];

            var A = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();
            var NL = new int[800000];
            foreach (var a in A)
            {
                NL[a]++;
            }
            var Sum = A.Sum();

            var vals2 = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();

            var Q = vals2[0];

            for (int i = 0; i < Q; i++)
            {
                var v = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();
                int B = v[0], C = v[1];

                Sum = Sum - NL[B] * B + NL[B] * C;
                NL[C] += NL[B];
                NL[B] = 0;

                Console.WriteLine(Sum);

            }

            //Console.WriteLine();
            Console.Out.Flush();
        }




    }
}


