#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, sum = 0;
  cin >> n;
  std::vector<long long int> v(n + 1, 0);
  std::vector<long long int> a(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  long long int q;
  cin >> q;
  std::vector<long long int> b(q + 1, 0);
  std::vector<long long int> c(q + 1, 0);
  for (int i = 1; i <= q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 1; i <= q; ++i) {
    replace(a.begin(), a.end(), b[i], c[i]);
    cout << accumulate(a.begin(), a.end(), sum) << "\n";
  }
  return 0;
}
