#include <bits/stdc++.h>
using namespace std;
int a[100005];
int boom[100005];
int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    boom[a[i]]++;
  }
  cin >> q;
  long long ans = 0;
  for (long long i = 1; i < 100005; i++) {
    ans += i * boom[i];
  }
  for (long long i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    if (boom[a] != 0) {
      boom[b] += boom[a];
      ans -= boom[a] * (a - b);
      cout << ans << endl;
    } else
      cout << ans << endl;
  }
  return 0;
}
