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( );

        int Q = int.Parse( Console.ReadLine( ) );
        for ( int i = 0; i < Q; i++ )
        {
            var input = Console.ReadLine( ).Split( ).Select( long.Parse ).ToArray( );
            for ( int j = 0; j < numbers.Count(); j++ )
            {
                if ( numbers[j] == input[0] )
                {
                    numbers[ j ] = input[ 1 ];
                }
            }
            Console.WriteLine(numbers.Sum());
        }

       


    }

}


