#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


signed main(){ 
    int n; cin>>n;
    vector<int> A(20000000,0);
    int a[n];
    rep(i, n) a[i] = 0;
    for(int i=0;i<n;i++){
        int ai; cin>>ai;
        a[i]=ai;
        A[ai]+=1;
    }

    int q; cin>>q;
    
    vector<int> scores;

    //cout<<result<<endl;
    int result = accumulate(a,a+n,0);
    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        result=result+(c-b)*A[b];
        A[c]+=A[b];
        A[b]=0;

        scores.push_back(result);
    }

    for(int i=0;i<q;i++){
        cout<<scores[i]<<endl;
    }
}  
