#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
void chmin(T &a, const T &b) noexcept {
  if (b < a) a = b;
}
template <class T>
void chmax(T &a, const T &b) noexcept {
  if (a < b) a = b;
}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &...args) {
  cout << x << " ";
  debug_out(args...);
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  map<int, int> mp;
  ll sum = 0;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (mp.count(b)) {
      sum -= b * mp[b];
      sum += c * mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
    }
    cout << sum << "\n";
  }
  return 0;
}
