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