#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll n,q;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  cin>>q;
  ll b[q],c[q];
  for(ll i=0;i<q;i++){
    cin>>b[i]>>c[i];
  }
  for(ll i=0;i<q;i++){
    ll ans=0;
    for(l j=0;j<n;j++){
      if(a[j]==b[i]){
        a[j]=c[i];
      }
      ans+=a[j];
    }
    cout<<ans<<endl;
  }
  return 0;
}