#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n;
  cin >> n;
  long long a[n], sum = 0;
  int freq[100005];
  for (int i = 0; i < 100005; i++) freq[i] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    freq[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum = sum - freq[b] * b + freq[b] * c;
    freq[c] += freq[b];
    freq[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
