#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int64_t N;
  cin >> N;
  int64_t sum = 0;
  vector<int64_t> A;
  for (int64_t i = 0; i < N; i++) {
    int64_t tmp;
    cin >> tmp;
    A.push_back(tmp);
    sum += tmp;
  }
  int64_t Q;
  cin >> Q;
  int64_t B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B;
    cin >> C;
    int64_t sub = C - B;
    for (int j = 0; j < A.size(); j++) {
      if (A[j] == B) {
        A[j] = C;
        sum += sub;
      }
    }
    std::cout << sum << endl;
  }
  return 0;
}
