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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n=Readint();
            //string[] str = Console.ReadLine().Split(' ');

            int n = Readint();

            var a = new int[n];
            a = ReadArray(n);

            int q = Readint();

            var count = new int[100001];
            for(int i = 0; i < n; i++)
            {
                count[a[i]]++;
            }

            long sum = a.Sum();


            for (int i = 0; i < q; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                int b = int.Parse(str[0]);
                int c = int.Parse(str[1]);

                sum += count[b] * (c - b);
                Cout(sum);

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


            //ここまで
        }

        static void Cout(string s)
        {
            Console.WriteLine(s);
            return;
        }

        static void Cout(int n)
        {
            Console.WriteLine(n);
            return;
        }

        static void Cout(long n)
        {
            Console.WriteLine(n);
            return;
        }

        static int Readint()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] ReadArray(int n)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i < n; i++){ a[i] = int.Parse(str[i]); }
            return a;
        }

        static long Readlong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int Min(int a, int b)
        {
            if (a < b) return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a > b) return a;
            return b;
        }


    }

}
