#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int *arr = new int[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    v.push_back(temp);
  }
  int q;
  cin >> q;
  for (int z = 0; z < q; z++) {
    int b, c;
    cin >> b >> c;
    auto it = find(v.begin(), v.end(), b);
    while (it != v.end()) {
      sum = sum - *it + c;
      *it = c;
      it = find(v.begin(), v.end(), b);
    }
    cout << sum << endl;
  }
  return 0;
}
