using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);

            str = Console.ReadLine ().Split (' ');
            int[] Count = new int[100000];

            for (int i = 0; i < 100000; i++)
            {
                Count[i] = 0;
            }

            long ans = 0;

            for (int i = 0; i < N; i++)
            {
                Count[int.Parse (str[i])] += 1;
                ans += int.Parse (str[i]);
            }

            int Q = int.Parse (Console.ReadLine ());

            for (int i = 0; i < Q; i++)
            {
                str = Console.ReadLine ().Split (' ');
                int B = int.Parse (str[0]);
                int C = int.Parse (str[1]);

                ans += Count[B] * (C - B);
                Console.WriteLine (ans);

                Count[C] += Count[B];
                Count[B] = 0;
            }

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}