#include <bits/stdc++.h>
using namespace std;
int ind[100005] = {};
int main() {
  int n;
  cin >> n;
  int a[n + 5];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ind[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum -= (ind[b] * b);
    ind[c] += ind[b];
    sum += (ind[b] * c);
    ind[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
