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

class Program
{
    static void Main(string[] args)
    {
        var n = ReadInt();
        var aList = ReadLongs().ToList();
        var q = ReadInt();
        var results = new List<long>();
        for (int i = 0; i < q; i++)
        {
            var inputs = ReadInts();
            var b = inputs[0];
            var c = inputs[1];

            aList = aList.Select(a => a == b ? c : a).ToList();
            results.Add(aList.Sum());
        }

        foreach (var result in results)
        {
            Console.WriteLine(result);
        }
    }


    private static string Read() => Console.ReadLine();
    private static char[] ReadChars() => Array.ConvertAll(Read().Split(), a => a[0]);
    private static int ReadInt() => int.Parse(Read());
    private static long ReadLong() => long.Parse(Read());
    private static double ReadDouble() => double.Parse(Read());
    private static int[] ReadInts() => Array.ConvertAll(Read().Split(), int.Parse);
    private static long[] ReadLongs() => Array.ConvertAll(Read().Split(), long.Parse);
    private static double[] ReadDoubles() => Array.ConvertAll(Read().Split(), double.Parse);
}