#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
int main() {
  int n, q;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for (const auto& e : mp) {
    ans += e.first * e.second;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    ans -= c * mp[c];
    ans -= b * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    ans += c * mp[c];
    cout << ans << endl;
  }
}
