#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<long long, long long> nums;
  for (long long i = 0; i < n; i++) {
    long long input;
    cin >> input;
    nums[input] += 1;
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    nums[c] += nums[b];
    nums.erase(nums.find(b));
    long long ans = 0;
    for (map<long long, long long>::iterator itr = nums.begin();
         itr != nums.end(); itr++) {
      ans += itr->first * itr->second;
    }
    cout << ans << endl;
  }
  return 0;
}
