#include <bits/stdc++.h>
using namespace std;
long long int t, n, tmp_a, tmp_b, sum = 0;
vector<long long int> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < v.size(); i++) {
    cin >> v[i];
    sum += v[i];
  }
  cin >> t;
  while (t--) {
    cin >> tmp_a >> tmp_b;
    for (int i = 0; i < v.size(); i++) {
      if (v[i] == tmp_a) {
        sum -= tmp_a;
        v[i] = tmp_b;
        sum += tmp_b;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
