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[q, n];
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < q; j++)
            {
                w[j, i] = a[i];
            }
        }
        for(int i = 0; i < q; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if(i == 0)
                    w[i, j] = a[j];
                else
                    w[i, j] = w[i - 1, j];
            }
            var b = ReadLine().Split().Select(int.Parse).ToArray();
            for(int j = 0; j < n; j++)
            {
                if(w[i, j] == b[0])
                    w[i, j] = b[1];
            }
        }
        long[] l = new long[q];
        for(int i = 0; i < q; i++)
        {
            for(int j = 0; j < n; j++)
            {
                l[i] += w[i, j];
            }
            WriteLine(l[i]);
        }
    }
}
