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