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