#include <bits/stdc++.h>
using namespace std;
vector<int> a;
bool binarysearch(int x, int y, int n) {
  int i = 0;
  while (i <= n) {
    int mid = i + (n - i) / 2;
    if (a[mid] == x) {
      a[mid] = y;
      return true;
    } else if (a[mid] > x)
      n = mid - 1;
    else
      i = mid + 1;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  a.assign(n, 0);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  sort(a.begin(), a.end());
  int q;
  cin >> q;
  int x, y;
  while (q--) {
    cin >> x >> y;
    while (binarysearch(x, y, n - 1) == true) {
      if (y > x)
        sum += (y - x);
      else
        sum -= (x - y);
      sort(a.begin(), a.end());
    }
    cout << sum << endl;
  }
}
