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

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

     public static void hoge()
    {
        var n = long.Parse(System.Console.ReadLine());
        var a = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var q = long.Parse(System.Console.ReadLine());

        var sum = a.Sum();
        var query = a.AsEnumerable();
        Dictionary<long, long> dic = new Dictionary<long, long>();

        for(long i = 0; i < q; i++)
        {
            var var = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var b = var[0];
            var c = var[1];
            query = query.Select(x => x == b ? c : x);
            Console.WriteLine(query.Sum());
        }

    }
}