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