#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void Main() {
  ll N, Q;
  cin >> N;
  vi A(N);
  for (ll i = 0, i_len = (N); i < i_len; ++i) {
    cin >> A[i];
  }
  cin >> Q;
  vvi inQ(Q, vi(2));
  for (ll i = 0, i_len = (Q); i < i_len; ++i) {
    cin >> inQ[i][0] >> inQ[i][1];
  }
  vi arrayInt(100001, 0);
  ll sum = 0;
  for (ll i = 0, i_len = (N); i < i_len; ++i) {
    sum += A[i];
    arrayInt[A[i]]++;
  }
  for (ll i = 0, i_len = (Q); i < i_len; ++i) {
    ll count = arrayInt[inQ[i][1]];
    arrayInt[inQ[i][1]] += arrayInt[inQ[i][0]];
    arrayInt[inQ[i][0]] = 0;
    sum += count * (inQ[i][1] - inQ[i][0]);
    cout << sum << "\n";
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  Main();
  cout << flush;
}
