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

class Program
{
    public static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }

    public void Exe()
    {
        int n = int.Parse(Console.ReadLine());
        List<int> rep_base = new List<int>(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
        int rep_num = int.Parse(Console.ReadLine());
        int cnt = 0;
        int[] rep_target;
        while(cnt < rep_num)
        {
            rep_target = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int from = rep_target[0];
            int to = rep_target[1];
            for(int i = 0; i < n; i++)
            {
                if(rep_base[i] == from)
                {
                    rep_base[i] = to;
                }
            }
            this.WriteSum(rep_base);
            cnt++;
        }
    }
    private void WriteSum(List<int> list)
    {
        int sum = 0;
        foreach(int item in list)
        {
            sum += item;
        }
        Console.WriteLine(sum);
    }
}

