#include <bits/stdc++.h>
using namespace std;
using p = pair<int, int>;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> A(100005);
  for (int i = 0; i < (n); ++i) {
    cin >> a.at(i);
    A.at(a.at(i))++;
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    int tmp;
    tmp = A.at(b);
    A.at(b) = 0;
    A.at(c) += tmp;
    int sum = 0;
    for (int k = 0; k < (100001); ++k) {
      sum += k * A.at(k);
    }
    cout << sum << endl;
  }
  return 0;
}
