#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>
using Graph = vector<vector<int>>

const double PI = acos(-1);
const int MAX = 100005;

int main() {
    int a,n,q;
  	ll X[MAX];
    vector<int> v;
    cin >> n;
    rep(i,n) {
        cin >> a;
        X[a]++;
    }
    cin >> q;
    vector<ll> sum(q+1);
  	sum[0] = 0;
    rep(i,MAX) {
        sum[0] += i * X[i];
    }
    for(int i = 1; i <= q; ++i) {
        int b,c;
        cin >> b >> c;
        ll tmp_b = X[b];
        X[b] = 0;
        X[c] += tmp_b;
        
        sum[i] = sum[i-1] - tmp_b*b + tmp_b*c;
    }
    
    for(int i = 1; i <= q; ++i) cout << sum[i] << "\n";
    return 0;
}