#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);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    for (int i = 0; i < N; i++) {
      if (A.at(i) == B) A.at(i) = C;
    }
    int sum = 0;
    for (int s : A) {
      sum += s;
    }
    cout << sum << endl;
  }
}
