#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  uint64_t n;
  cin >> n;
  int a[n];
  int sum = 0;
  map<uint64_t, uint64_t> m;
  for (uint64_t i = 0; i < (n); i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  uint64_t q;
  cin >> q;
  for (uint64_t i = 0; i < (q); i++) {
    uint64_t k, l;
    cin >> k >> l;
    sum += (l * m[k]) - (k * m[k]);
    cout << sum << "\n";
    m[l] += m[k];
    m[k] = 0;
  }
  return 0;
}
