#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
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), c(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < (q); ++i) {
    ll ans = 0;
    for (int j = 0; j < (n); ++j) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
      ans += a[j];
    }
    cout << ans << endl;
  }
  return 0;
}
