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

namespace ABC171
{
    using static Ex;
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_D();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var a = Read[0];
            if ('a' <= a && a <= 'z') 'a'.Cw();
            else 'A'.Cw();
        }
    }
    public class ABC_B
    {
        int n, k;
        public ABC_B()
        {
            (n, k) = ReadIntArray().ToTpl2();
            var p = ReadIntArray().OrderBy(v => v).ToArray();
            long ans = 0;
            for (int i = 0; i < k; i++) ans += p[i];
            ans.Cw();
        }
    }
    public class ABC_C
    {
        long n, pre;
        char[] arr;
        public ABC_C()
        {
            n = ReadLong;

            if (n <= 26)
            {
                var c = (char)('a' + n - 1);
                c.Cw();
                return;
            }

            long a = 0;
            long tmp = 26;
            int i = 2;
            for (; ; i++)
            {
                //i.Cw();
                a += tmp;
                tmp *= 26;
                if (tmp + a >= n) break;
            }
            arr = new char[i];
            for (int j = 0; j < i; j++)
            {
                arr[j] = 'a';
            }
            pre = a;
            //rec(i - 1, false, false);
            A(n, tmp + a, i - 1);
            string.Join("", arr).Cw();
        }

        void rec(int i, bool b, bool bb)
        {
            //$"{pre} {i} {b} { string.Join("", arr)}".Cw();
            if (pre >= n) return;

            for (int j = b ? 1 : 0; j < 26; j++)
            {
                //if (arr[i] == (char)('a' + j)) continue;
                arr[i] = (char)('a' + j);
                pre++;
                if (pre >= n) return;

                if (i + 1 < arr.Length) rec(i + 1, true, true);
                $"{pre} {i} {b} { string.Join("", arr)}".Cw();
                if (pre >= n) return;
            }
            string.Join("", arr).Cw();
            arr[i] = 'a';
            string.Join("", arr).Cw();
            if (bb) return;
            rec(i - 1, true, false);
        }

        void A(long n, long max, int i)
        {
            bool bo = false;
            var tmp = n - pre;
            while (i >= 0)
            {
                var a = tmp / 26;
                var b = tmp % 26;
                //$"{n} {pre} {a} {b}".Cw();

                arr[i] = b == 0 ? 'z' : (char)('a' + b - 1);
                i--;
                tmp = a + (bo ? 0 : 1);
                //a.Cw();
                if (a % 26 == 0 && !bo) tmp--;
                bo = (a == 0);
            }
        }
    }
    public class ABC_D
    {
        long b, c;
        public ABC_D()
        {
            var n = ReadLong;
            var a = ReadLongArray();
            var q = ReadLong;

            var arr = new Dictionary<long, long>();
            for (long i = 0; i < (long)1e5 + 1; i++)
            {
                arr[i] = 0;
            }
            foreach (var v in a)
            {
                arr[v]++;
            }
            long res = 0;
            for (long i = 0; i < (long)1e5 + 1; i++)
            {
                res += arr[i] * i;
            }

            for (long i = 0; i < q; i++)
            {
                (b, c) = ReadIntArray().ToTpl2();

                res -= arr[b] * b;
                res += arr[b] * c;

                arr[c] += arr[b];
                arr[b] = 0;
                res.Cw();
            }
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }

    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }



        public static bool Mins<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
        public static bool Maxs<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
        public static void Swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
        public static void Swap<T>(List<T> list, int i, int j) { T tmp = list[j]; list[j] = list[i]; list[i] = tmp; }

        public static long Lcm(int x, int y) { return x / Gcd(x, y) * y; }
        public static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); }
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var v = new string[N]; for (long i = 0; i < N; ++i) v[i] = Read; return v; }
        public static int[] ReadIntArray(long N) { var v = new int[N]; for (long i = 0; i < N; ++i) v[i] = ReadInt; return v; }
        public static long[] ReadLongArray(long N) { var v = new long[N]; for (long i = 0; i < N; ++i) v[i] = ReadLong; return v; }

        public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
        public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
        public static (T, T, T, T) ToTpl4<T>(this T[] v) { return (v[0], v[1], v[2], v[3]); }
        public static (T, T, T, T, T) ToTpl5<T>(this T[] v) { return (v[0], v[1], v[2], v[3], v[4]); }


        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

        /// <summary>
        /// lower_boundは、探索したいkey以上のイテレータを返す
        /// upper_boundは、探索したいkeyより大きいイテレータを返す
        public static int UpperBound<T>(List<T> a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(List<T> a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Count - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}

Measured memory_bytes: 55780