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