#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    
    int q;
    cin>>q;
    vector<int> b(q);
    vector<int> c(q);
    rep(i,q) cin>>b[i]>>c[i];
    
    vector<int> num(100005,0);
    rep(i,n) num[a[i]]++;
    int sum=accumulate(a.begin(),a.end(),0);
    
    rep(i,q){
        sum +=(c[i]-b[i])*num[b[i]];
        cout<<sum<<endl;
        num[C[i]]+=num[b[i]];
        b[i]=0;
    }
    
    return 0;
}