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

namespace ABC0613
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<long> inp = Console.ReadLine().Split(" ").Select(long.Parse).ToList();
            int q = int.Parse(Console.ReadLine());
            List<long> ans = new List<long>();
            int b = 0;
            int c = 0;
            for(int i=0;i<q;i++)
            {
                string[] str = Console.ReadLine().Split(" ");
                b = int.Parse(str[0]);c = int.Parse(str[1]);

                var hoge = inp
                    .Select((p, ind) => new { Content = p, Index = ind })
                    .Where(ano => ano.Content == b)
                    .Select(ano => ano.Index)
                    .ToList();
                foreach (int j in hoge)
                {
                    inp[j] = c;
                }
                ans.Add(inp.Sum());
            }
            foreach(long s in ans)
            {
                Console.WriteLine(s);
            }
        }
    }
}
