#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
using Graph = vector<vector<int>>;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> cnt(N);
  ll MAX = 0;
  ll sum = 0;
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
    ++cnt[A[i]];
    chmax(MAX, A[i]);
    sum += A[i];
  }
  int Q;
  cin >> Q;
  vector<P> S;
  for (int i = 0; i < (Q); i++) {
    int a, b;
    cin >> a >> b;
    S.emplace_back(P(a, b));
  }
  for (int i = 0; i < (Q); i++) {
    ll a = S[i].first;
    ll b = S[i].second;
    sum -= (ll)(a * cnt[a]);
    sum += (ll)(b * cnt[a]);
    cnt[b] += cnt[a];
    cnt[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
