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


class Program
{

    public static void Main( )
    {
        int N = int.Parse( Console.ReadLine( ) );
        var numbers = Console.ReadLine( ).Split( ).Select( long.Parse ).ToList( );
        var ans = new List<long>( );

        int Q = int.Parse( Console.ReadLine( ) );
        for ( int i = 0; i < Q; i++ )
        {
            var input = Console.ReadLine( ).Split( ).Select( long.Parse ).ToArray( );
            numbers = numbers.Select( x => Replace(x, input[0], input[1] ) ).ToList( );
            Console.WriteLine( numbers.Sum() );
        }



    }

    public static long Replace( long target, long a, long b )
    {
        if ( target==a )
        {
            return b;
        }
        return target;
    }

}
