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