#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) cin >> b.at(i) >> c.at(i);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    mp[a.at(i)]++;
  }
  long long cnt = 0;
  for (auto x : mp) {
    cnt += x.first * x.second;
  }
  for (int i = 0; i < q; i++) {
    int tmp = mp[b.at(i)];
    mp[b.at(i)] = 0;
    mp[c.at(i)] += tmp;
    cnt -= tmp * b.at(i);
    cnt += c.at(i) * tmp;
    cout << cnt << endl;
  }
  return 0;
}
