#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> num(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num.at(i);
  }
  int Q, x1, x2;
  long long kekka = 0;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> x1 >> x2;
    for (int j = 0; j < N; j++) {
      if (x1 == num.at(j)) {
        num.at(j) = x2;
      }
    }
    for (int j = 0; j < N; j++) {
      kekka += num.at(j);
    }
    cout << kekka << endl;
    kekka = 0;
  }
}
