#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, q, ans;
  vector<int> a(200000), b(200000), c(200000);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> 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++) {
    for (int j = 0; j < n; j++) {
      if (a.at(j) == b.at(i)) a.at(j) = c.at(i);
    }
    cout << accumulate(a.begin(), a.end(), 0) << endl;
  }
  return 0;
}
