#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long n, b, c, q, sum = 0;
  cin >> n;
  vector<long> a(n);
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  sort(a.begin(), a.end());
  cin >> q;
  for (auto i = 0; i < q; i++) {
    cin >> b >> c;
    for (auto j = 0; j < n; j++) {
      if (a[j] == b) {
        a[j] = c;
        sum = sum - b + c;
      } else if (a[j] > b) {
        break;
        cout << j << " ";
      }
    }
    cout << sum << "\n";
    sort(a.begin(), a.end());
  }
  return 0;
}
