#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  map<int, int> A;
  long long S = 0;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    S += tmp;
    if (A.count(tmp))
      A.at(tmp)++;
    else
      A[tmp] = 1;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C, numB;
    cin >> B >> C;
    if (A.count(B)) {
      numB = A.at(B);
      A.at(B) = 0;
      S -= B * numB;
      S += C * numB;
      if (A.count(C))
        A.at(C) += numB;
      else
        A[C] = numB;
    }
    cout << S << endl;
  }
}
