#include<bits/stdc++.h>
using namespace std;

int main(void){
  int N,a,b; long long sum=0; cin >> N;
  vector<int> Q(100001,0);
  while(N--){cin >> a; sum+=a; ++Q[a];}
  cin >> N;
  while(N--){cin >> a >> b; sum+=(b-a)*Q[a]; Q[b]+=Q[a]; Q[a]=0; cout << sum << endl;}
  return 0;
}
