#include <bits/stdc++.h>
using namespace std;
int64_t sum(vector<int64_t> V) {
  int64_t S = 0;
  for (int64_t i = 0; i < V.size(); i++) {
    S += V.at(i);
  }
  return S;
}
int main() {
  int64_t N, Q;
  cin >> N;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  cin >> Q;
  vector<vector<int64_t>> BC(Q, vector<int64_t>(2));
  for (int64_t i = 0; i < Q; i++) {
    for (int64_t j = 0; j < 2; j++) {
      cin >> BC.at(i).at(j);
    }
  }
  int64_t S;
  for (int64_t i = 0; i < Q; i++) {
    S = 0;
    for (int64_t j = 0; j < N; j++) {
      if (A.at(j) == BC.at(i).at(0)) {
        A.at(j) = BC.at(i).at(1);
      }
    }
    S = sum(A);
    cout << S << endl;
  }
}
