#include <bits/stdc++.h>
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;
}
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int main() {
  int n;
  cin >> n;
  int q;
  vector<int> a(n);
  vector<int> cnt(100005);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  cin >> q;
  vector<int> b(q), c(q);
  int sum = 0;
  for (int i = 0; i < a.size(); i++) {
    sum += a[i];
  }
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    if (cnt[b[i]] != 0) {
      cnt[c[i]] += cnt[b[i]];
      sum -= (b[i] - c[i]) * cnt[b[i]];
      cnt[b[i]] = 0;
    }
    cout << sum << "\n";
  }
  return 0;
}
