#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  cin>>n;
  vector<long long >nos(100001,0);
  long long sum=0;
  for(int i=0,a;i<n;i++){cin>>a;sum+=a;nos[a]+=1;}
  int k;cin>>k;
  int b,c;
  for(int i=0;i<k;i++){
  	cin>>b>>c;
    sum = sum-nos[b]*b+nos[b]*c;
    nos[c]+=nos[b];
    nos[b]=0;
    cout<<sum<<'\n';
  }
}