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