#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << "[ " << *it << " = " << a << " ] ";
  err(++it, args...);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  unordered_map<long long int, long long int> mp;
  long long int sum = 0;
  for (long long int i = 0, a; i < n; i++) {
    cin >> a;
    mp[a]++;
    sum += a;
  }
  long long int Q;
  cin >> Q;
  while (Q--) {
    long long int a, b;
    cin >> a >> b;
    if (mp.count(a)) {
      sum -= mp[a] * a;
      mp[b] += mp[a];
      sum += mp[a] * b;
    }
    cout << sum << '\n';
  }
  return 0;
}
