#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
int main() {
  int n;
  cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < int(n); i++) cin >> v[i];
  int q;
  cin >> q;
  int b, c;
  ll ans;
  for (int i = 0; i < int(q); i++) {
    cin >> b >> c;
    ans = 0;
    for (int j = 0; j < int(n); j++) {
      if (v[j] == b) {
        v[j] = c;
        ans += c;
      } else {
        ans += v[j];
      }
    }
    cout << ans << endl;
  }
}
