#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template <typename T>
void ndarray(vector<T> &vec, int len) {
  vec.resize(len);
}
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec) ndarray(v, args...);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  ll s;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    s += a[i];
  }
  int q;
  cin >> q;
  vector<ll> b(n);
  vector<ll> c(n);
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  ll dp[10010];
  for (int i = 0; i < (10010); ++i) dp[i] = 0;
  for (int i = 0; i < (n); ++i) ++dp[a[i]];
  for (int i = 0; i < (q); ++i) {
    s = s - dp[b[i]] * (b[i] - c[i]);
    cout << s << "\n";
    dp[c[i]] += dp[b[i]];
    dp[b[i]] = 0;
  }
  return 0;
}
