#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1
 
void testCase() {
    int n;
    cin >> n;
    ll sum = 0;
    int fre[100007] = {0};
    for (int i=0; i<n; i++) {
        int v;
        cin >> v;
        fre[v]++;
        sum += v;
    }
    int q;
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        sum = sum - b*fre[b];
        sum = sum + c*fre[b];
        fre[c] += fre[b];
        fre[b] = 0;
        cout << sum << endl;
    }
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}