#include <bits/stdc++.h>
using namespace std;
int main(void) {
  unsigned long long N, Q;
  cin >> N;
  vector<unsigned long long> A(N);
  for (unsigned long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  vector<unsigned long long> B(Q);
  vector<unsigned long long> C(Q);
  for (unsigned long long i = 0; i < Q; i++) {
    cin >> B[i];
    cin >> C[i];
  }
  for (unsigned long long i = 0; i < Q; i++) {
    for (unsigned long long j = 0; j < N; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
    }
    unsigned long long sum = accumulate(A.begin(), A.end(), 0);
    cout << sum << endl;
  }
  return 0;
}
