#include <bits/stdc++.h>
using namespace std;
using L = long long;
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);
  vector<int> c(q);
  for (int i = 0; i < q; ++i) {
    cin >> b.at(i);
    cin >> c.at(i);
  }
  for (int i = 0; i < q; ++i) {
    replace(a.begin(), a.end(), b[i], c[i]);
    int sum = 0;
    sum = accumulate(a.begin(), a.end(), 0);
    cout << sum << endl;
  }
  return 0;
}
