using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var n = Sarray()[0];
            var an = Sarray();
            var q = Sarray()[0];
            for(var i=0;i<q;i++)
            {
                var bc = Sarray();
                for (var j = 0; j < n; j++)
                {
                    if (an[j] == bc[0]) an[j] = bc[1];
                }
                WriteLine(an.Sum());
            }
        }
    }
}
