#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  vector<ll> A(10011, 0);
  cin >> N;
  ll sum = 0;
  for (ll i = 0; i < (N); i++) {
    ll x;
    cin >> x;
    A[x]++;
    sum += x;
  }
  ll Q;
  cin >> Q;
  for (ll z = 0; z < (Q); z++) {
    ll s, t;
    cin >> s >> t;
    ll v;
    v = A[s];
    A[t] += v;
    ll ret = (t - s) * v;
    sum = sum + ret;
    cout << sum << endl;
  }
}
