#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  map<int, int> m;
  for (long long i = 0; i < N; ++i) {
    int A;
    cin >> A;
    if (auto it = m.find(A); it != end(m))
      it->second++;
    else
      m.insert(make_pair(A, 1));
  }
  int Q;
  cin >> Q;
  vector<long long> S(Q);
  for (long long i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    if (auto it_b = m.find(B); it_b != end(m)) {
      if (auto it_c = m.find(C); it_c != end(m)) {
        m[C] += m[B];
        m[B] = 0;
      } else {
        m.insert(make_pair(C, m[B]));
        m[B] = 0;
      }
    }
    long long ans = 0;
    for (auto a : m) {
      ans += a.first * a.second;
    }
    S[i] = ans;
  }
  for (auto s : S) cout << s << endl;
}
