#include<bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main()
{
  ll n;
  cin>>n;
  vector<ll> a(100005);
  ll sum=0;
  for(ll i=0;i<n;i++){
    ll k;
    cin>>k;

    sum+=k;
    a[k]++;
  }
  ll q;cin>>q;

  while(q--)
  {
    ll b,c;
    cin>>b>>c;
    sum-=a[b]*b;
    sum+=a[b]*c;

    a[c]+=a[b];
    a[b]=0;

    cout<<sum<<"\n";
  }

  return 0;
}
