#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a.at(i);
  }
  int q;
  cin >> q;
  long long sum = 0;
  for (int i = 0; i < (n); ++i) {
    sum += a.at(i);
  }
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < (n); ++i) {
      long long dif = 0;
      if (a.at(i) == b) {
        a.at(i) = c;
        dif += c - b;
      }
      sum += dif;
    }
    cout << sum << endl;
  }
}
