#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll factorial(int i) {
  if (i == 0) return 1;
  return (factorial(i - 1)) * i;
}
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  int a[110000];
  ll ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> A[i];
    a[A[i]]++;
    ans += A[i];
  }
  int q;
  cin >> q;
  vector<vector<int>> d(q, vector<int>(2));
  for (int i = 0; i < (int)(q); i++) cin >> d[i][0] >> d[i][1];
  cout << ans << endl;
  for (int i = 0; i < (int)(q); i++) {
    ans += (d[i][1] - d[i][0]) * a[d[i][0]];
    a[d[i][1]] += a[d[i][0]];
    a[d[i][0]] = 0;
    cout << ans << endl;
  }
}
