#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  vector<int> count(100001, 0);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    count.at(A.at(i))++;
  }
  cin >> Q;
  int B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    sum = sum - B * count.at(B) + C * count.at(B);
    count.at(C) += count.at(B);
    count.at(B) = 0;
    printf("%lld\n", sum);
  }
  return 0;
}
