#include <bits/stdc++.h>
const unsigned long long int mod = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int n;
  cin >> n;
  map<unsigned long long int, unsigned long long int> aa;
  vector<unsigned long long int> a(n);
  for (unsigned long long int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    ++aa[v];
  }
  unsigned long long int sum = 0;
  unsigned long long int q;
  cin >> q;
  vector<pair<int, int>> bc(q);
  for (unsigned long long int i = 0; i < q; ++i) {
    int g, h;
    cin >> g >> h;
    bc[i].first = g;
    bc[i].second = h;
  }
  bc.erase(unique(bc.begin(), bc.end()), bc.end());
  for (int i = 0; i < q; ++i) {
    aa[bc[i].second] += aa[bc[i].first];
    aa[bc[i].first] = 0;
    for (auto i : aa) {
      sum += (i.second) * (i.first);
    }
    cout << sum << "\n";
    sum = 0;
  }
}
