#include <bits/stdc++.h>

using namespace std;
#define long long int
const int N = 1e5 + 10;
long long A[N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n;
    cin >> n;
    map<int, int> qtd;
    long long sum = 0LL;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
        sum += A[i];
        qtd[A[i]]++;
    }
    int q;
    cin >> q;
    while(q--) {
        int b, c;
        cin >> b >> c;
        int qtd_ = qtd[b];
        qtd[b] = 0, qtd[c] += qtd_;
        long long b_ = b * qtd_;
        long long c_ = c * qtd_;
        long long ans = sum - b_;
        ans += c_;
        sum = ans;
        cout << ans << "\n";
    }
    
    return 0;
}
