#include <bits/stdc++.h>
using namespace std;

#define endl            "\n"
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>=c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
void output_vector(const vector<T> , bool ,bool ,int ,int );

template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);

template<typename T>
istream& operator>>(istream &in,vector<T> &v);


void solve()
{   
    int n,q,b,c;cin>>n;
    int a[100005];memset(a,0,sizeof(a));
    ll sum=0;
    fr(i,0,n){int x;cin>>x;sum+=x;a[x]++;}
    cin>>q;debug1(sum);
    fr(i,0,q){
        cin>>b>>c;
        // deb2(b,c);
        sum+=a[b]*(c-b);
        a[c]+=a[b];
        a[b]-=a[b];
        // deb3(sum,a[b],a[c]);
        cout<<sum<<endl;
    }
}

int main()
{   

    FIO;
    ll test;test=1;
    // cin>>test;
    while(test--)
    solve();
    return 0;
}






template<typename T>
void output_vector(const vector<T> &v, bool debug_print=false,bool add_one = false,int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        (debug_print)?(cerr << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n')):(cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'));
}   

template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<" ":out<<"\n";    
    }
    return out;
}

template<typename T>
istream& operator>>(istream &in,vector<T> &v){
    for(T &i:v)
        in>>i;
    return in;
}

Measured memory_bytes: 3964