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

int main() {
    int n;
    cin >> n;
    int a;
    long long s = 0;
    vector<int> an(100001, 0);
    for (int i = 0; i < n; i++) {
        cin >> a;
        s += a;
        an[a]++;
    }
    
    int q;
    cin >> q;
    vector<int> b(q + 1);
    vector<int> c(q + 1);
    for (int i = 1; i <= q; i++) {
        cin >> b[i] >> c[i];
    }
    
    for (int i = 1; i <= q; i++) {
        s += an[b[q]] * (c[q] - b[q]);
        an[c[q]] += an[b[q]];
        an[b[q]] = 0;
        
        cout << s << endl;
    }
}