#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  vector<int> count(100000 + 5, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    count.at(a)++;
  }
  cin >> q;
  int64_t init_ans = 0;
  for (int a = 1; a <= n; a++) {
    init_ans += a * count.at(a);
  }
  vector<int64_t> ans(q + 1, 0);
  ans.at(0) = init_ans;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    ans.at(i + 1) = ans.at(i) + (c - b) * count.at(b);
    count.at(c) += count.at(b);
    count.at(b) = 0;
  }
  for (int i = 0; i < q; i++) {
    cout << ans.at(i + 1) << endl;
  }
  return 0;
}
