#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz size()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ld long double
#define sqr(x) (x)*(x)

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef pair < int, int > pii;
typedef vector < int >  vi;
typedef vector < vector < int> > vvi;
typedef pair < int, pair < int, int> > piii;
typedef vector < pair < int, int > > vpii;
typedef vector < ll >  vll;

bool valid(int x, int y, int n, int m){
    return x > 0 && x <= n && y > 0 && y <= m;
}

ll gcd(ll a, ll b){
    if(b == 0){
        return a;
    }
    return gcd(b , a % b);
}

ll nok(ll a, ll b){
    return (a / gcd(a, b) * b);
}

ld dist(ll x, ll y, ll x2, ll y2){
    return sqrt(sqr(x - x2) + sqr(y - y2));
}


void solve() {
    int n;
    cin >> n;
    vi a(n + 3);
    vi cnt(100100, 0);
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
        cnt[a[i]]++;
    }
    int q;
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        int k = cnt[b];
        cnt[b] = 0;
        sum -= (k * b);
        sum += (k * c);
        cnt[c] += k;
        cout << sum << "\n";
    }
}

signed main() {
    fast_io;
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}



