#include <iostream>

using namespace std;

typedef pair<ll,ll> p;
#define MAX (int)1e5
typedef long long int ll;

ll num[MAX+1];
p trans[MAX];
int main(void){
  for(int i=0;i<=MAX;i++){
    num[i] = 0;
  }
  int N;
  cin >> N;
  for(int n=0;n<N;n++){
    int tmp;
    cin >> tmp;
    num[tmp] += 1;
  }
  int Q;
  cin >> Q;
  ll ans = 0;
  for(int n=1;n<=MAX;n++){
    ll tmp = num[n];
    tmp = tmp * (ll)n;
    ans += tmp;
  }
  for(int q=0;q<Q;q++){
    int b,c;
    cin >> b >> c;
    trans[q] = make_pair(b,c);
  }
  for(int q=0;q<Q;q++){
    ll b,c;
    b = trans[q].first;
    c = trans[q].second;
    ans = ans - b*num[b] + c*num[b];
    num[c] += num[b];
    num[b] = 0;
    cout << ans << endl;
  }
  return 0;
}