#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> s(100000, 0);
  int64_t sum = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    s[c[i]] += s[b[i]];
    sum += (s[c[i]] - s[b[i]]) * b[i];
    s[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
