#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;
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 main() {
  int n;
  cin >> n;
  vi a(n);
  for (int((i)) = (int)(0); ((i)) < (int)((n)); ++((i))) cin >> a[i];
  vi cnt(10005);
  for (int((i)) = (int)(0); ((i)) < (int)((n)); ++((i))) cnt[a[i]]++;
  ll ans = 0;
  for (int((i)) = (int)(0); ((i)) < (int)((10005)); ++((i))) {
    ans += i * cnt[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    ll x = (c - b) * cnt[b];
    ans += x;
    cout << ans << endl;
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  return 0;
}
