# include <iostream>
using namespace std; 
int main(){
  int n,i,sum,temp,a,t,b;
  int mod=1e5;
  cin>>n; 
  int ar[n];
  int arr[mod+1]={0};
  sum=0;
  for(i=0;i<n;i++){
    cin>>ar[i];
    sum=sum+ar[i];
    arr[ar[i]]++;
  }
  cin>>t; 
  while(t--){
    cin>>a>>b; 
    if(arr[a]>0){
      temp=(b-a);
      sum=sum+(arr[a])*temp; 
      arr[b]+=arr[a];
      arr[a]=0;
    }
    cout<<sum; 
    cout<<"\n";
  }
  return 0;
}