#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<long long> a, b, c, count;
  long long sum = 0;
  int n, q;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> q;
  b.resize(q);
  c.resize(q);
  count.resize(*max_element(a.begin(), a.end()), 0);
  for (int i = 0; i < n; i++) {
    count[a[i] - 1]++;
  }
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
    sum += (c[i] - b[i]) * count[b[i] - 1];
    count[c[i] - 1] += count[b[i] - 1];
    count[b[i] - 1] = 0;
    cout << sum << '\n';
  }
}
