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

ll main()
{
    ll N, Q;
    ll A_sum[100001] = {};
    vector<ll> S;
    cin >> N;
    ll total = 0;

    for (ll i = 0; i < N; i++) {
        ll A;
        cin >> A;
        A_sum[A] += A;
        total += A;
    }
    cin >> Q;
    for (ll i = 0; i < Q; i++) {
        ll B, C;
        cin >> B >> C;
        total += (A_sum[B] / B) * C - A_sum[B];
        A_sum[C] += (A_sum[B] / B) * C;
        A_sum[B] = 0;
        S.push_back(total);
    }
    for (ll i = 0; i < Q; i++) {
        cout << S[i] << endl;
    }
    return 0;
}
