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