#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int i,j;

int main(){
    /*int n,q;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    cin>>q;
    int b[q],c[q];
	ll s[q]={0};
    for(i=0;i<q;i++) cin>>b[i]>>c[i];
    for(i=0;i<q;i++){
    	for(j=0;j<n;j++){
    		if(a[j]==b[i])a[j]=c[i];
    		s[i]+=a[j];
		}
		cout<<s[i]<<endl;
	}*/
	int n,q;
    cin>>n;
    int a[n],g[n]={0};
	ll s=0;
    for(i=0;i<n;i++){
    	cin>>a[i];
    	g[a[i]]++;
    	s+=a[i];
	}
    cin>>q;
    int b[q],c[q];
    for(i=0;i<q;i++) cin>>b[i]>>c[i];
    for(i=0;i<q;i++){
    	if(c[i]-b[i]>=0)
    	    s+=g[b[i]]*(c[i]-b[i]);
    	if(c[i]-b[i]<0)
		    s-=g[b[i]]*(b[i]-c[i]);
		g[c[i]]+=g[b[i]];
		cout<<s<<endl;
	}
	return 0;
}