#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vll cnt(n + 1);
  ll tot = 0;
  for (int i = 1; i <= (int)(n); i++) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  for (int i = 1; i <= (int)(n); i++) tot += i * cnt[i];
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    tot -= cnt[b];
    tot -= cnt[c];
    cnt[b] = 0;
    tot += b * cnt[b];
    tot += c * cnt[c];
    cout << tot << endl;
  }
  return 0;
}
