#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int p, int r, int num) {
  if (p <= r) {
    int mid = (p + r) / 2;
    if (arr[mid] == num) return mid;
    if (arr[mid] > num) return binarySearch(arr, p, mid - 1, num);
    if (arr[mid] > num) return binarySearch(arr, mid + 1, r, num);
  }
  return -1;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  int sum = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    for (int j = 0; j < q; j++) {
      sort(a, a + n);
      int index = binarySearch(a, 0, n, b);
      if (index != -1) {
        sum = sum - b + c;
        a[index] = c;
      } else {
        break;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
