#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> v(1);
  int a = 0;
  cin >> a;
  v.at(0).push_back(a);
  v.at(0).push_back(1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    bool exist = false;
    for (int j = 0; j < v.size(); j++) {
      if (a == v.at(j).at(0)) {
        v.at(j).at(1) += 1;
        exist = true;
      }
    }
    if (exist == false) {
      v.push_back(vector<int>());
      v.at(v.size() - 1).push_back(a);
      v.at(v.size() - 1).push_back(1);
    }
  }
  int q, b, c;
  long long s;
  cin >> q;
  for (int i = 0; i < q; i++) {
    s = 0;
    cin >> b >> c;
    for (int j = 0; j < v.size(); j++) {
      if (v.at(j).at(0) == b) {
        v.at(j).at(0) = c;
      }
      s += v.at(j).at(0) * v.at(j).at(1);
    }
    cout << s << endl;
  }
  return 0;
}
