#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int l = 0, r = n - 1;
    while (l <= r) {
      int m = l + (r - l) / 2;
      if (a[m] == b)
        a[m] = c;
      else if (a[m] < b)
        l = m + 1;
      else
        r = m - 1;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
