#include <bits/stdc++.h>
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 ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} INIT;
signed main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < ll(N); ++i) cin >> A[i];
  ll sum = 0;
  map<ll, ll> m;
  for (ll i = 0; i < ll(N); ++i) {
    m[A[i]]++;
    sum += A[i];
  }
  ll Q;
  cin >> Q;
  for (ll i = 0; i < ll(Q); ++i) {
    ll a, b;
    cin >> a >> b;
    if (!m.count(a)) {
      m[a] = 0;
    }
    sum += (b - a) * m[a];
    m[b] += m[a];
    cout << sum << "\n";
  }
  return 0;
}
