#include <bits/stdc++.h>
long double constexpr pi = 3.141592653589793;
template <class T>
constexpr T sigma1(T i, T n) {
  return (n - i + 1) * (i + n) / 2;
}
template <class T>
constexpr T sigma2(T i, T n) {
  return (i == 1 ? n * (n + 1) * (2 * n + 1) / 6
                 : sigma2(1, n) - sigma2(1, i - 1));
}
template <class T>
constexpr T sigma3(T i, T n) {
  if (i == 1) {
    auto temp = sigma1(i, n);
    return temp * temp;
  }
  return sigma2(1, n) - sigma2(1, i - 1);
}
template <size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  return b = (unsigned long long)b + 1;
}
template <size_t i>
std::bitset<i> operator++(std::bitset<i> b) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  auto temp = b;
  b++;
  return temp;
}
template <size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  return b = (unsigned long long)b - 1;
}
template <size_t i>
std::bitset<i> operator--(std::bitset<i> b) {
  static_assert(i <= 64, "Cannot cast 64bit int.");
  auto temp = b;
  b--;
  return temp;
}
long long constexpr inf = std::numeric_limits<long long>::max();
using namespace std;
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  long long n;
  cin >> n;
  vector<long long> a(n);
  unordered_map<long long, long long> m;
  for (long long i = 0; i < (n); ++i) {
    cin >> a[i];
    ++m[a[i]];
  }
  long long s = accumulate(a.begin(), a.end(), 0);
  long long q;
  cin >> q;
  for (long long i = 0; i < (q); ++i) {
    long long b, c;
    cin >> b >> c;
    long long x = m[b];
    m[b] = 0;
    m[c] += x;
    cout << (s -= (b - c) * x) << "\n";
  }
  return 0;
}
