#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, q, ans = 0;
  vector<int> a(200000), b(200000), c(200000), count(200000, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    count.at(a.at(i))++;
    ans += a.at(i);
  }
  cin >> q;
  for (int i = 0; i < q; i++) cin >> b.at(i) >> c.at(i);
  for (int i = 0; i < q; i++) {
    ans += (c.at(i) - b.at(i)) * count.at(b.at(i));
    count.at(c.at(i)) += count.at(b.at(i));
    count.at(b.at(i)) = 0;
    cout << ans << endl;
  }
  return 0;
}
