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