#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  sort(a.begin(), a.end());
  vector<int> sum(q, 0);
  bool flg = false;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
        flg = true;
        if (flg = true && a[j] != b[i]) {
          flg = false;
          break;
        }
      }
    }
    for (int j = 0; j < n; j++) {
      sum[i] += a[j];
    }
  }
  for (int i = 0; i < q; i++) {
    cout << sum[i] << endl;
  }
}
