#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<long long> ans(q);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    auto itr = find(a.begin(), a.end(), b);
    while (itr != a.end()) {
      a[distance(a.begin(), itr)] = c;
      itr = find(a.begin(), a.end(), b);
    }
    ans[i] = (long long)accumulate(a.begin(), a.end(), 0);
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
