#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  long long int su = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    mp[arr[i]]++;
    su += arr[i];
  }
  int q;
  cin >> q;
  vector<long long int> res;
  for (int i = 0; i < q; i++) {
    int a;
    int b;
    cin >> a >> b;
    if (mp.find(a) != mp.end()) {
      int x = mp[a];
      su = su - a * x;
      su = su + b * x;
      mp[b] += x;
      mp.erase(a);
    }
    res.push_back(su);
  }
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << endl;
  }
  return 0;
}
