using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        var q = int.Parse(ReadLine());
        int[] w = new int[n];
        Copy(a, w, n);
        long l = 0;
        for(int i = 0; i < q; i++)
        {
            var b = ReadLine().Split().Select(int.Parse).ToArray();
            for(int j = 0; j < n; j++)
            {
                if(w[j] == b[0])
                    w[j] = b[1];
            }
            for(int j = 0; j < n; j++)
            {
                l += w[j];
            }
            WriteLine(l);
            l = 0;
        }
    }
}
