#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n;
  cin>>n;
  ll a;
  map<ll,ll> mp;
 ll sum=0;
  for(ll i=0;i<n;i++)
  {
   cin>>a;
    sum+=a;
    mp[a]++;
  }
  ll q;
  cin>>q;
  ll x,y;
  while(q--)
  {
   cin>>x>>y;
    sum-=mp[x]*x;
    sum+=mp[x]*y;
    mp[y]+=mp[x];
    mp[x]=0;
    cout<<sum<<endl;
  }
  

}
