#include <bits/stdc++.h>
using namespace std;
const int mAX = 1e5;
int main() {
  long long int n, q, b[mAX], c[mAX], a[mAX], sum = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (long long int j = 0; j < q; j++) {
    sum = 0;
    for (long long int i = 0; i < n; i++) {
      if (b[j] == a[i]) a[i] = c[j];
      sum += a[i];
    }
    cout << sum << endl;
  }
}
