#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, b, c, q;
  long long int sum = 0;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    sum = 0;
    int j = 0;
    cin >> b >> c;
    while (a[j] <= b) {
      if (a[j] == b) a[j] = c;
      j++;
    }
    sum = accumulate(a.begin(), a.end(), 0);
    sort(a.begin(), a.end());
    cout << sum << endl;
  }
  return 0;
}
