#include <bits/stdc++.h>
using std::abs;
using std::accumulate;
using std::acos;
using std::acosh;
using std::all_of;
using std::any_of;
using std::asin;
using std::asinh;
using std::atan;
using std::atanh;
using std::binary_search;
using std::bitset;
using std::cerr;
using std::cin;
using std::clog;
using std::complex;
using std::cos;
using std::cosh;
using std::count;
using std::cout;
using std::deque;
using std::equal_range;
using std::exp;
using std::fill;
using std::find;
using std::imag;
using std::ios_base;
using std::log;
using std::log10;
using std::lower_bound;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::minmax;
using std::minmax_element;
using std::next_permutation;
using std::none_of;
using std::norm;
using std::nth_element;
using std::pair;
using std::partial_sort;
using std::polar;
using std::pow;
using std::prev_permutation;
using std::priority_queue;
using std::queue;
using std::real;
using std::reverse;
using std::rotate;
using std::set;
using std::set_difference;
using std::set_intersection;
using std::set_union;
using std::shuffle;
using std::sin;
using std::sinh;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::stack;
using std::stoi;
using std::stol;
using std::string;
using std::swap;
using std::tan;
using std::tanh;
using std::to_string;
using std::tuple;
using std::unique;
using std::upper_bound;
using std::vector;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
inline void in(T &p) {
  cin >> p;
}
template <class T1, class T2>
inline void in(T1 &p1, T2 &p2) {
  cin >> p1 >> p2;
}
template <class T1, class T2, class T3>
inline void in(T1 &p1, T2 &p2, T3 &p3) {
  cin >> p1 >> p2 >> p3;
}
template <class T1, class T2, class T3, class T4>
inline void in(T1 &p1, T2 &p2, T3 &p3, T4 &p4) {
  cin >> p1 >> p2 >> p3 >> p4;
}
template <class T1, class T2, class T3, class T4, class T5>
inline void in(T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5) {
  cin >> p1 >> p2 >> p3 >> p4 >> p5;
}
template <class T>
inline void ins(T &p) {
  for_each((p).begin(), (p).end(), in<decltype(p[0])>);
}
template <class T>
inline void out(T p) {
  cout << p << "\n";
}
template <class T1, class T2>
inline void out(T1 p1, T2 p2) {
  cout << p1 << " " << p2 << "\n";
}
template <class T1, class T2, class T3>
inline void out(T1 p1, T2 p2, T3 p3) {
  cout << p1 << " " << p2 << " " << p3 << "\n";
}
template <class T1, class T2, class T3, class T4>
inline void out(T1 p1, T2 p2, T3 p3, T4 p4) {
  cout << p1 << " " << p2 << " " << p3 << " " << p4 << "\n";
}
inline void out(ld p) { printf("%.12Lf\n", p); }
template <class T>
inline void outml(T p) {
  for_each((p).begin(), (p).end(), out<decltype(p[0])>);
}
template <class T>
inline void outol(T V) {
  auto n = V.size();
  for (auto i = (0); i <= (n - 1); ++i) cout << V[i] << " \n"[i == n - 1];
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int n, q, b, c;
long sum;
map<int, int> m;
inline void solve(void) {
  in(n);
  vector<int> a(n);
  ins(a);
  for (auto i = (0); i <= (n - 1); ++i) {
    m[a[i]]++;
    sum += a[i];
  }
  in(q);
  for (auto i = (0); i <= (q - 1); ++i) {
    in(b, c);
    sum -= m[b] * b;
    sum += m[b] * c;
    out(sum);
    m[c] += m[b];
    m[b] = 0;
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return EXIT_SUCCESS;
}
