#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int arr_len;
  map<int, int> num_cnt;
  cin >> arr_len;
  for (int i = 0; i < arr_len; i++) {
    int num;
    cin >> num;
    if (num_cnt.find(num) == num_cnt.end()) {
      num_cnt[num] = 1;
    } else {
      num_cnt[num] += 1;
    }
  }
  int query_len;
  cin >> query_len;
  long long sum = 0;
  for (auto nc = num_cnt.begin(); nc != num_cnt.end(); nc++) {
    sum += nc->first * nc->second;
  }
  for (int i = 0; i < query_len; i++) {
    int b, c;
    cin >> b >> c;
    if (num_cnt.find(b) != num_cnt.end()) {
      sum -= b * num_cnt[b];
      sum += c * num_cnt[b];
      if (num_cnt.find(c) == num_cnt.end()) {
        num_cnt[c] = num_cnt[b];
      } else {
        num_cnt[c] += num_cnt[b];
      }
      num_cnt[b] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
