#include <iostream>
#include <set>
using namespace std;
int main(int argc, char* argv[])
{
	int N,i,Q;
	cin>>N;
	multiset<int> mySet;
	multiset<int>::iterator sit;
	int A;
	for (i=0;i<N;i++){
		cin>>A;
		mySet.insert(A);
	}
	cin>>Q;
	int B,C;
	for (i=0;i<Q;i++){
		cin>>B>>C;
		/*while (true){
			sit=mySet.find(B);
			if (sit==mySet.end()){
				break;
			}
			mySet.erase(sit);
			mySet.insert(C);
		}*/
		int ans=0;
		for (sit=mySet.begin();sit!=mySet.end();sit++){
			if (*sit==B){
				*sit=C;
			}
			ans+=*sit;
		}
		cout<<ans<<endl;
	}
	return 0;
}