#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  unordered_map<int, int> mp;
  for (auto& ele : arr) {
    mp[ele]++;
  }
  int q;
  cin >> q;
  vector<int> a(q), b(q);
  vector<unsigned long long int> ans;
  unsigned long long int sum = accumulate(arr.begin(), arr.end(), 0);
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i];
    if (mp.count(a[i])) {
      sum += (mp[a[i]] * (b[i] - a[i]));
      mp[b[i]] += mp[a[i]];
      mp.erase(a[i]);
    }
    ans.push_back(sum);
  }
  for (auto& ele : ans) {
    cout << ele << endl;
  }
  return 0;
}
