#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> kazu(100005, 0);
  set<int> exsi;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    kazu[a]++;
    exsi.insert(a);
  }
  cin >> q;
  vector<int64_t> ans(q);
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    int tmp = kazu[b];
    kazu[b] = 0;
    exsi.erase(b);
    kazu[c] += tmp;
    exsi.insert(c);
    int64_t now = 0;
    for (auto j : exsi) {
      now += j * kazu[j];
    }
    ans[i] = now;
  }
  for (int i = 0; i < (int)(q); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
