#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) cin >> b[i] >> c[i];
  int i, j;
  for (i = 0; i < q; i++) {
    ll ans = 0;
    for (j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
        ans += a[j];
      } else {
        ans += a[j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
