#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), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  int a = 0;
  vector<int> m(100000);
  for (int i = 0; i < N; i++) {
    m.at(A.at(i) - 1)++;
    a += A.at(i);
  }
  int x;
  for (int i = 0; i < Q; i++) {
    x = C.at(i) - B.at(i);
    a += (x * m.at(B.at(i) - 1));
    cout << a << endl;
    m.at(C.at(i) - 1) += m.at(B.at(i) - 1);
    m.at(B.at(i) - 1) = 0;
  }
}
