#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, b, c;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    std::replace(a.begin(), a.end(), b, c);
    cout << std::accumulate(a.begin(), a.end(), 0) << endl;
  }
}
