#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long n, s = 0, q, b, c;
  cin >> n;
  long long a[n];
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    s += a[i];
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> b >> c;
    s = s - m[b] * b;
    s = s + m[b] * c;
    m[c] += m[b];
    m[b] = 0;
    cout << s;
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}
