#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;
  int b[q][2];
  for (int i = 0; i < q; i++) {
    cin >> b[i][0] >> b[i][1];
  }
  for (int i = 0; i < q; i++) {
    sort(a, a + n);
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i][0]) {
        a[j] = b[i][1];
      } else if (b[i][0] < a[j]) {
        break;
      }
    }
    cout << accumulate(a, a + n, 0) << endl;
  }
}
