#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long sum = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  long long Q;
  cin >> Q;
  long long B, C;
  for (long long i = 0; i < Q; i++) {
    cin >> B >> C;
    for (long long j = 0; j < N; j++) {
      if (A.at(j) == B) {
        A.at(j) = C;
        sum += C - B;
      }
    }
    cout << sum << endl;
  }
}
