#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
  int N;cin>>N;
  vector<ll>A(100001,0);
  ll sum=0;
  for(int i=0;i<N;i++){
    int a;cin>>a;
    A[a]+=1;
    sum+=a;
  }
  int Q;cin>>Q;
  while(Q--){
    int b,c;
    cin>>b>>c;
    sum+=A[b]*(c-b);
    A[c]+=A[b];
    A[b]=0;
    cout<<sum<<endl;
  }
}