#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);
  }
  int64_t f = 0;
  for (int k = 0; k < n; k++) {
    f += A.at(k);
  }
  int q;
  cin >> q;
  vector<vector<int>> B(q, vector<int>(2));
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> B.at(i).at(j);
    }
  }
  for (int i = 0; i < 1; i++) {
    int count;
    count = 0;
    for (int j = 0; j < n; j++) {
      if (A.at(j) == B.at(i).at(0)) {
        A.at(j) = B.at(i).at(1);
        count++;
      }
    }
    if (count > 0) {
      f = f - count * (B.at(i).at(0) - B.at(i).at(1));
    }
    cout << f << endl;
  }
  for (int i = 1; i < q; i++) {
    if (B.at(i).at(0) == B.at(i - 1).at(0)) {
      cout << f << endl;
      continue;
    }
    int count;
    count = 0;
    for (int j = 0; j < n; j++) {
      if (A.at(j) == B.at(i).at(0)) {
        A.at(j) = B.at(i).at(1);
        count++;
      }
    }
    if (count > 0) {
      f = f - count * (B.at(i).at(0) - B.at(i).at(1));
    }
    cout << f << endl;
  }
}
