#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, q, ans = 0;
  cin >> n;
  ll a[100001] = {};
  for (int i = 0; i < (int)(n); ++i) {
    int x;
    cin >> x;
    ans += x;
    a[x]++;
  }
  cin >> q;
  vector<ll> b(q), c(q);
  for (int i = 0; i < (int)(q); ++i) cin >> b[i] >> c[i];
  for (int i = 0; i < (int)(q); ++i) {
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
    ans += (c[i] - b[i]) * a[b[i]];
    cout << ans << endl;
  }
  return 0;
}
