#include <bits/stdc++.h>
using namespace std;
map<int, int> findfreq(const vector<int>& vec) {
  map<int, int> M;
  for (unsigned int i = 0; i < vec.size(); i++) {
    if (M.find(vec[i]) == M.end()) {
      M[vec[i]] = 1;
    } else {
      M[vec[i]]++;
    }
  }
  return M;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int num;
  int n;
  cin >> n;
  vector<int> vec;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    vec.push_back(num);
  }
  map<int, int> myfreq = findfreq(vec);
  int q;
  cin >> q;
  long long sum;
  int b, c;
  sum = accumulate(vec.begin(), vec.end(), 0);
  while (q--) {
    cin >> b >> c;
    int count = myfreq.at(b);
    sum += count * (c - b);
    myfreq.at(c) += count;
    cout << sum << '\n';
  }
  return 0;
}
