#include <bits/stdc++.h>
using namespace std;
void Ash() {}
void solve() {
  int freq[100001] = {0};
  int n, x, q, a, b, sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> x, ++freq[x], sum += x;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> a >> b;
    if (freq[a] != 0) {
      sum += freq[a] * (b - a);
      freq[b] += freq[a];
      freq[a] = 0;
    }
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  Ash();
  solve();
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  ;
  return 0;
}
