#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[i];
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    for (int i = 0; i < N; i++) {
      if (A[i] == B) {
        A[i] = C;
      }
    }
    long sum = 0;
    for (int i = 0; i < N; i++) {
      sum += A[i];
    }
    cout << sum << endl;
  }
  return 0;
}
