using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        var dic = new DefaultDectionary<int, int>(0);

        for(int i=0; i<n; i++) {
            dic[aa[i]] += 1;
        }

        long sum = 0;
        foreach (var x in dic) {
            sum += x.Key * x.Value;
        }

        var sb = new StringBuilder();

        var q = int.Parse(input.ReadLine());
        for(int i=0; i<q; i++) {
            var spl = input.ReadLine().Split(' ');
            var b = int.Parse(spl[0]);
            var c = int.Parse(spl[1]);

            if (dic.ContainsKey(b)) {
                sum -= b * dic[b];
                sum += c * dic[b];

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

            sb.AppendLine(sum.ToString());
        }
        return sb;
    }

    class DefaultDectionary<Tkey, TValue> : Dictionary<Tkey, TValue>
    {
        TValue DefaultValue;
        public DefaultDectionary(TValue defaultvalue) {
            this.DefaultValue = defaultvalue;
        }
        public new TValue this[Tkey key] {
            get {
                if (this.ContainsKey(key)) return base[key];
                else return DefaultValue;
            }
            set {
                base[key] = value;
            }
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        if(n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}
