#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q, i, j, a[100002], b, c, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  sort(a, a + n);
  for (i = 0; i < q; i++) {
    sum = 0;
    cin >> b >> c;
    for (j = 0; j < n; j++) {
      if (a[j] == b)
        a[j] = c;
      else if (a[j] > b)
        break;
    }
    for (j = 0; j < n; j++) {
      sum = sum + a[j];
    }
    cout << sum << "\n";
    sort(a, a + n);
  }
  return 0;
}
