#include <iostream>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int N,Q;
    ll sum=0;
    cin>>N;
    map<int,int> m;
    rep(i,N){
        int a;
        cin>>a;
        sum+=a;
        m[a]++;
    }
    cin>>Q;
    rep(i,Q){
        int b,c,nb;
        cin>>b>>c;
        if(m[b]==0){
            cout << sum << endl;
        }else{
            nb = m[b];
            m[b] = 0;
            m[c] += nb;
            sum = sum - nb*b + nb*c;
            cout << sum << endl;
        }
    }

    return 0;
}