#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1001001001;
using ll = long long;
using P = pair<int, int>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = (0); i <= (n - 1); ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = (0); i <= (q - 1); ++i) cin >> b[i] >> c[i];
  vector<int> cnt(n + 1);
  ll ans = 0;
  for (int i = (0); i <= (n - 1); ++i) {
    cnt[a[i]]++;
    ans += a[i];
  }
  for (int i = (0); i <= (q - 1); ++i) {
    ll minus = (ll)b[i] * cnt[b[i]];
    ll add = (ll)c[i] * cnt[b[i]];
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    ans = ans + add - minus;
    cout << ans << endl;
  }
  return 0;
}
