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