#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> v;
  long long int x;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  long long int q, b, c, index;
  cin >> q;
  std::vector<long long int>::iterator it;
  for (long long int i = 0; i < q; i++) {
    cin >> b >> c;
    long long int ct = count(begin(v), end(v), b);
    while (ct > 0) {
      it = find(begin(v), end(v), b);
      index = it - v.begin();
      v[index] = c;
      ct--;
    }
    long long int sum = accumulate(begin(v), end(v), 0);
    cout << sum << "\n";
  }
  return 0;
}
