#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  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[q];
  int c[q];
  for (int i = 0; i < q; i++) {
    cin >> b[i];
    cin >> c[i];
  }
  sort(a, a + n);
  int flag = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
        sum += c[i] - b[i];
        flag = 1;
      } else if (a[j] == b[i] && flag == 1) {
        break;
      }
    }
    sort(a, a + n);
    cout << sum << endl;
  }
}
