#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec.at(i);
  }
  int q;
  cin >> q;
  vector<vector<int>> che(q, vector<int>(2));
  for (int i = 0; i < q; ++i) {
    cin >> che.at(i).at(0) >> che.at(i).at(1);
  }
  vector<int> num(100000);
  vector<int> lis;
  for (int i = 0; i < n; ++i) {
    num.at(vec.at(i) - 1) += 1;
  }
  for (int i = 0; i < q; ++i) {
    num.at(che.at(i).at(1) - 1) += num.at(che.at(i).at(0) - 1);
    num.at(che.at(i).at(0) - 1) = 0;
    int ans = 0;
    for (int j = 0; j < 100000; ++j) {
      ans += (j + 1) * num.at(j);
    }
    cout << ans << endl;
  }
}
