using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        long N = long.Parse(Console.ReadLine());
        long [] A =new long[N];
        String[] input = Console.ReadLine().Split();
        for(int i = 0; i < N; i++) { A[i] = long.Parse(input[i]); }
        long Q = long.Parse(Console.ReadLine());

        long[] B = new long[Q];
        long[] C = new long[Q];
        for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(); B[i] = long.Parse(input[0]); C[i] = long.Parse(input[1]); }

        for (int i = 0; i < Q; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (A[j] == B[i]) A[j] = C[i];
            }
            Console.WriteLine(A.Sum());
        }

    }
}