#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n + 5), bunpu(n + 10);
  ll tot = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    bunpu[a[i]]++;
    tot += a[i];
  }
  cin >> q;
  vector<int> b(q + 5), c(q + 5);
  for (int i = 0; i < (q); i++) cin >> b[i] >> c[i];
  for (int i = 0; i < (q); i++) {
    tot += (c[i] - b[i]) * bunpu[b[i]];
    bunpu[c[i]] += bunpu[b[i]];
    bunpu[b[i]] = 0;
    cout << tot << endl;
  }
  return 0;
}
