unittest
{
	assert( [ "4", "1 2 3 4", "3", "1 2", "3 4", "2 4" ].solve == "11\n12\n16" );
	assert( [ "4", "1 1 1 1", "3", "1 2", "2 1", "3 5" ].solve == "8\n4\n4" );
	assert( [ "2", "1 2", "3", "1 100", "2 100", "100 1000" ].solve == "102\n200\n2000" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto q = input.front.to!( long );
	auto bcs = new long[ 2 ][ q ];
	foreach( ref bc; bcs )
	{
		input.popFront;
		bc = input.front.split.to!( long[] );
	}
	
	auto t = 0L;
	auto ds = new long[ 1 + 10L ^^ 5 ];
	foreach( a; as )
	{
		t += a;
		ds[ a ]++;
	}
	
	auto anss = new long[ bcs.length ];
	foreach( ref ans, bc; lockstep( anss, bcs ) )
	{
		t = t - bc[ 0 ] * ds[ bc[ 0 ] ] + bc[ 1 ] * ds[ bc[ 0 ] ];
		ds[ bc[ 1 ] ] += ds[ bc[ 0 ] ];
		ds[ bc[ 0 ] ] = 0;
		ans = t;
	}
	return anss.to!( string[] ).join( "\n" );
}
