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