#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int a[200005] = {0};
  int n, q;
  cin >> n;
  int x, y;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    a[x]++;
  }
  cin >> q;
  while (q--) {
    cin >> x >> y;
    if (a[x] > 0) {
      sum -= x * a[x];
      sum += y * a[x];
      a[y] += a[x];
      a[x] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
