#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, b, c, sum = 0, in, q, ct;
  vector<long long> v;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> in;
    sum += in;
    v.push_back(in);
  }
  cin >> q;
  sort(v.begin(), v.end());
  for (long long i = 0; i < q; i++) {
    cin >> b >> c;
    for (long long i = 0; i < n; i++) {
      if (v[i] == b) {
        sum = sum - b + c;
        v[i] = c;
      }
    }
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
