#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t N, Q;
  vector<pair<size_t, size_t>> A;
  cin >> N;
  for (size_t i = 0; i < N; ++i) {
    size_t t;
    cin >> t;
    int j;
    for (j = 0; j < A.size(); ++j) {
      if (A[j].first == t) {
        A[j].second++;
        break;
      }
    }
    if (j == A.size()) {
      pair<size_t, size_t> pt;
      pt.first = t;
      pt.second = 1;
      A.push_back(pt);
    }
  }
  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 < A.size(); ++j) {
      if (A[j].first == b) {
        A[j].first = c;
      }
      sum += A[j].first * A[j].second;
    }
    cout << sum << endl;
  }
}
