
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;

    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = System.Console.ReadLine().Split(' ').ToArray();
            var q = int.Parse(Console.ReadLine());
            var b = new string[q];
            var c = new string[q];
            var ans = new decimal[q];
            for (int i = 0; i < q; i++)
            {
                var str = System.Console.ReadLine().Split(' ');
                b[i] = str[0];
                c[i] = str[1];

                ans[i] = 0;
                for (int j = 0; j < a.Length; j++)
                {
                    if (a[j] == b[i])
                    {
                        a[j] = c[i];
                    }
                    ans[i] += int.Parse(a[j]);
                }
            }

            try
            {
                for (int i = 0; i < q; i++)
                {
                    Output(ans[i].ToString());
                }
            }
            catch
            {
                Output(ans.ToString());
            }
        }
        private static void Output(string str)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            Console.WriteLine(str);

            Console.Out.Flush();
        }

    }