#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, n, l, a, b, c;
  long long c1 = 0;
  vector<long long> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    int q;
    cin >> q;
    v.push_back(q);
    c1 = c1 + q;
  }
  cin >> l;
  for (j = 0; j < l; j++) {
    cin >> b >> c;
    for (i = 0; i < n; i++) {
      if (v[i] == b) {
        c1 = (c1 - b) + c;
        v[i] = c;
      }
    }
    cout << c1 << endl;
  }
  return 0;
}
