#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	int t=1;
	while(t)
	{
		int n; cin>>n; int a[n]; f(i,n) cin>>a[i];
		int z=pow(10,5)+1;
		int v[z]={0};
		ll sum=0;
		f(i,n)
		{
			sum=sum+a[i];
			v[a[i]]++;
		}
		int q; cin>>q;
		while(q)
		{
			int b,c; cin>>b>>c;
			int temp=v[b];
			v[b]=0;
			v[c]=v[c]+temp;
			sum=sum-temp*b;
			sum=sum+temp*c;
			cout<<sum<<"\n";
			q--;
		}
		t--;
	}
	return 0;
}