#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = (int)2e5 + 5;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 5;
map<int, ll> mp, bp;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (mp[x] > 0) {
      ans -= (x * mp[x]);
      ans += (mp[x] * y);
      mp[y] += mp[x];
    }
    cout << ans << "\n";
  }
  return 0;
}
