#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, num, q1, q2;
  cin >> n;
  vector<int> nums(10e5, 0);
  vector<pair<int, int> > queries;
  int max_sum = 0;
  while (n--) {
    cin >> num;
    nums[num]++;
    max_sum += num;
  }
  cin >> q;
  while (q--) {
    cin >> q1;
    cin >> q2;
    queries.push_back(make_pair(q1, q2));
  }
  for (int i = 0; i < queries.size(); i++) {
    int num_first = nums[queries[i].first];
    nums[queries[i].second] += nums[queries[i].first];
    nums[queries[i].first] = 0;
    int sum = (queries[i].second - queries[i].first) * num_first;
    max_sum += sum;
    cout << to_string(max_sum) << endl;
  }
  return 0;
}
