using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var list = new List<(int b, int c)>();
        int n = int.Parse(Console.ReadLine());
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        var dic = new Dictionary<int, int>();
        foreach (int ele in arr)
        {
            if (!dic.ContainsKey(ele))
            {
                dic.Add(ele, 1);
            }
            else
            {
                dic[ele]++;
            }
        }
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
            int[] arr2 = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
            int b = arr2[0];
            int c = arr2[1];
            list.Add((b, c));
        }
        for (int i = 0; i < q; i++) {
            long sum = 0;
            int b = list[i].b;
            int c = list[i].c;
            if (!dic.ContainsKey(b))
            {
                foreach (var ele in dic)
                {
                    sum += ele.Key * ele.Value;
                }
                Console.WriteLine(sum);
                continue;
            }
            else
            {
                if (!dic.ContainsKey(c))
                {
                    dic.Add(c, dic[b]);
                    dic.Remove(b);
                }
                else
                {
                    dic[c] += dic[b];
                    dic.Remove(b);
                }
            }
            foreach (var ele in dic)
            {
                sum += ele.Key * ele.Value;
            }
            Console.WriteLine(sum);
        }
    
        
    }

    

}