#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i);
    cin >> C.at(i);
  }
  vector<int64_t> S(Q);
  vector<int64_t> T(Q + 1);
  for (int j = 0; j < N; j++) T.at(0) += A.at(j);
  for (int i = 0; i < Q; i++) {
    int count = 0;
    int dis = C.at(i) - B.at(i);
    for (int k = 0; k < N; k++) {
      if (A.at(k) == B.at(i)) {
        count++;
        A.at(k) = C.at(i);
      }
    }
    T.at(i + 1) = T.at(i) + dis * count;
    S.at(i) = T.at(i + 1);
  }
  for (int i = 0; i < Q; i++) cout << S.at(i) << endl;
}
