#include <bits/stdc++.h>
using namespace std;
using  ll=long long;
 
int main(){
  ll n,k=0;
  cin >> n;
  vector<ll> a(100000);
  for(int i=0;i<n;i++){
    ll x;
    cin >> x;
    k+=x;
    a[x-1]++;
  }
  
  ll q;
  cin >> q;
  
  for(int i=0;i<q;i++){
    ll b,c;
    cin >> b >> c;
    ll x=a[b-1];
    a[b-1]=0;
    a[c-1]+=x;
    k+=(c-b)*x;
    cout << k << endl;
  }
}