#include <bits/stdc++.h>
using namespace std;
typedef int pInt[4];
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &x : v) in >> x;
  return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
  out << "[" << p.first << ", " << p.second << "]"
      << "\n";
  return out;
}
template <class T1, class T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr long long MAX = 100010;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  cin >> A;
  long long s = accumulate((A).begin(), (A).end(), 0LL);
  vector<long long> cnt(N, 0);
  for (auto x : A) cnt[x]++;
  int Q;
  cin >> Q;
  while (Q--) {
    long long b, c;
    cin >> b >> c;
    long long diff = (c - b);
    s += diff * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << s << endl;
  }
}
