#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  vector<long long int> vec(n);
  long long int in;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    mp[vec[i]]++;
  }
  long long int sum = 0;
  for (auto i : mp) {
    sum += i.first * i.second;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (mp.count(b)) {
      int count = mp[b];
      sum -= b * count;
      mp.erase(b);
      mp[c] += count;
      sum += c * count;
    }
    cout << sum << "\n";
  }
  return 0;
}
