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