using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(input[i]);
        }

        int q = int.Parse(Console.ReadLine());
        int[,] bc = new int[q, 2];

        for (int i = 0; i < q; i++)
        {
            input = Console.ReadLine().Split(' ');
            bc[i, 0] = int.Parse(input[0]);
            bc[i, 1] = int.Parse(input[1]);
        }

        List<int> aa = new List<int>(a);
        for (int i = 0; i < q; i++)
        {
            while (true)
            {
                int index = aa.IndexOf(bc[i, 0]);
                if (index != -1)
                {
                    aa[index] = bc[i, 1];
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine(aa.Sum());
        }
    }
}
