#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  cin >> q;
  vector<pair<int, int>> bc(q);
  for (int i = 0; i < (q); i++) cin >> bc[i].first >> bc[i].second;
  vector<int> qty(100001);
  for (int i = 0; i < (n); i++) qty[a[i]]++;
  for (int i = 0; i < (q); i++) {
    int before = bc[i].first;
    int after = bc[i].second;
    qty[after] += qty[before];
    qty[before] = 0;
    long long sum = 0;
    for (int j = 1; j < qty.size(); j++) {
      sum += qty[j] * j;
    }
    cout << sum << endl;
  }
}
