#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q;
  cin >> N;
  vector<long long> A(N);
  vector<long long> num(100000 + 1, 0);
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
    num.at(A.at(i))++;
  }
  cin >> Q;
  vector<long long> ans(Q + 1);
  ans.at(0) = accumulate(A.begin(), A.end(), 0);
  for (long long i = 1; i <= Q; i++) {
    ans.at(i) = ans.at(i - 1);
    long long B, C;
    cin >> B >> C;
    long long D = C - B;
    ans.at(i) += (num.at(B) * D);
    num.at(C) += num.at(B);
    num.at(B) = 0;
  }
  for (long long i = 1; i <= Q; i++) cout << ans.at(i) << endl;
}
