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