#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a;
  int l;
  int i = 0, answer = 0;
  while (i < n) {
    cin >> l;
    answer += l;
    a.push_back(l);
    i++;
  }
  int q;
  cin >> q;
  i = 0;
  int b, c;
  while (i < q) {
    cin >> b >> c;
    auto itr = std::find(a.begin(), a.end(), b);
    while (itr != a.end()) {
      *itr = c;
      answer += (c - b);
      itr = std::find(itr, a.end(), b);
    }
    cout << answer << endl;
    i++;
  }
  return 0;
}
